c# - Reading AuthorizationSection from web.config provides incorrect values -


edit #2: config.filepath showing it's looking @ different file i'm expecting: "c:\windows\microsoft.net\framework64\v4.0.30319\config\web.config". expecting use web.config in project. need figure out why that's happening.

i have method in web api i'm trying read values authorization section in web.config. based on i've found, should work:

    public authorizationsetting getauthorizationsettings()     {         var config = webconfigurationmanager.openwebconfiguration(null);         var section = config.getsection("system.web/authorization") authorizationsection;          foreach (authorizationrule rule in section.rules)         {             if (rule.action.tostring().tolower() == "allow")             {                 debug.writeline(rule);             }         }          return new authorizationsetting();     } 

and section of web.config contains authorization info:

  <system.web>     <compilation debug="true" targetframework="4.5" />     <httpruntime targetframework="4.5" />     <identity impersonate="true" />     <authentication mode="windows" />     <authorization>       <allow roles="role1,role2,role3"/>       <deny users="*"/>     </authorization>   </system.web> 

you can see there 1 allow , 1 deny. when run code, appears there 1 rule. shouldn't there 2 since there allow , deny? , 1 rule looks have action of allow , "*" users. that's not what's in web.config. missing here?

enter image description here

** edit ** i've considered possibility it's reading different web.config file. there 1 other web.config file in solution (under views). changed have same authorization section, still same result.

as figured out using null in path parameter of openwebconfiguration loads server root web.config in

%systemroot%\microsoft.net\framework64\v4.0.30319\config\ 

the documentation says:

the virtual path configuration file. if null, root web.config file opened.

but 1 assume root web config of site, not server. anyway, try using:

var config = webconfigurationmanager.openwebconfiguration("~"); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -