locked
Membership Provider Parameters disappear after first request RRS feed

  • Question

  • User1307844667 posted

    I am trying to Initialize SQL Membership Provider by code and everything is working fine in the first request only!. When the code below executes again (after refreshing the page for example) I get the following error:

    The attribute 'connectionStringName' is missing or empty.

    Page Load Code:

    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>



    Download Sample Code from attachment tab

    https://connect.microsoft.com/VisualStudio/feedback/details/813107/membership-provider-parameters-disappear-after-first-request 

    Tuesday, February 4, 2014 3:08 AM

Answers

  • User697462465 posted

    Hi KhaledMusaied,

    Your membership provider's config section needs a connectionStringName attribute. Without that connectionStringName, it doesn't know what database to look for membership information in.

    You need to add the following code in your config file:

    <configuration>
      <connectionStrings>
        <add name="ConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
      </connectionStrings>
    

    Hope it helps.

    Best Regards,
    Terry Guo

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 5, 2014 6:43 AM