2014-01-07 154 views
1

初始化成員資格提供我試圖通過代碼來初始化SQL成員資格提供程序,一切都僅在第一要求做工精細! 當下面的代碼再次執行(清爽例如頁面後)我收到以下錯誤通過代碼

屬性「的connectionStringName」缺少或爲空。

頁面加載代碼:

MembershipSection membershipSection = (MembershipSection)ConfigurationManager.GetSection("system.web/membership"); 
        string sqlProviderName = "AspNetSqlMembershipProvider"; 
        NameValueCollection providerConfig; 
        providerConfig = membershipSection.Providers[sqlProviderName].Parameters; // returning empty list in the second request 
        var _SqlProvider = new SqlMembershipProvider(); 
        _SqlProvider.Initialize(sqlProviderName, providerConfig); 

Web.config文件:

<membership defaultProvider="AspNetSqlMembershipProvider"> 
     <providers> 
     <clear /> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Encrypted" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" applicationName="/" /> 
     </providers> 
    </membership> 

什麼建議嗎?

+0

微軟的答案! https://connect.microsoft.com/VisualStudio/feedback/details/813107/membership-provider-parameters-disappear-after-first-request –

回答

0

如何只讓您的數據/的ConnectionString/OBJ在靜態水平(像單身)?

它不喜歡的ConnectionString將是整個網絡情況的變化,不是嗎?

static string/dataType _DataToBeRead1timeOnly = null; 
static string/dataType DataToBeRead1timeOnly 
{ 
    get { 
    if (_DataToBeRead1timeOnly == null) { _DataToBeRead1timeOnly = .... } 
    return _DataToBeRead1timeOnly; 
    } 
} 
+0

謝謝,但這是一種解決方法,我可以緩存任何內容,但我相信網絡。 config配置已被緩存。 –