【问题标题】:Access to web.config attributes (not appSettings)访问 web.config 属性(不是 appSettings)
【发布时间】:2011-03-23 10:10:46
【问题描述】:

鉴于我可以向股票会员提供程序添加各种属性,我假设我可以对自己的提供程序实现做同样的事情。

<add name="MyMembershipProvider" type="Portal.Infrastructure.MyMembershipProvider"
             enablePasswordRetrieval="false"
                enablePasswordReset="true"
                requiresQuestionAndAnswer="true"
                [...] />

我现在的问题是:如何在代码中访问这些值?我知道 ConfigurationManager 可用于访问 appSettings 部分中的键值对,但这是不同的。

【问题讨论】:

  • 恕我直言,这些默认情况下不应该在您的提供程序类中提供吗?

标签: asp.net asp.net-mvc-2


【解决方案1】:

我不知道您尝试访问哪个部分,但一般的想法是您可以通过以下方式直接访问 WebConfig:

Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);  
// Get the object related to the <identity> section.
IdentitySection section = (IdentitySection)config.GetSection("system.web/identity");

而不是 IdentitySection 放你的部分。

【讨论】:

    猜你喜欢
    • 2012-03-24
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多