简体   繁体   English

从web.config的位置标记创建/访问自定义配置部分

[英]Create/Access Custom Configuration Section from location tag of web.config

I want to add some setting for various location and also want to access that per page basis 我想为各种位置添加一些设置,并且还希望按页面访问该设置

<location path="Account" myAttr="true">
  <system.web>
     <authorization>
        <allow users="*" />
     </authorization>
  </system.web>
</location>

Or I want to use 或者我想用

<location path="Account">
  <myNode>true</myNode>
  <system.web>
     <authorization>
        <allow users="*" />
     </authorization>
  </system.web>
</location>

Now I want to access this setting in code. 现在,我想在代码中访问此设置。 I am using MVC3 with ASP.net 4.0 . 我在ASP.net 4.0中使用MVC3。 I found an MSDN article on Custom Sections . 我在“自定义部分”上找到了MSDN文章。

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx http://msdn.microsoft.com/zh-CN/library/2tw134k3.aspx

I am not able to use that in location tags. 我无法在位置标记中使用它。

You can try to add ~ to the path : <location path="~/Account/LogIn"> 您可以尝试在路径中添加~<location path="~/Account/LogIn">

and I didn't use any true ... (and it works well). 而且我没有使用任何true ...(而且效果很好)。

Maybe you should add suitable class and attributes. 也许您应该添加合适的类和属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM