Solved

Membership.Getuser() works in asp.net 2.0 but not in asp.net 4.5

Posted on 2013-06-26
2
675 Views
Last Modified: 2013-06-26
aspx file

    string strUserName = User.Identity.Name;
    MembershipUser currentUser = Membership.GetUser(strUserName);

Default Membership Provider could not be found.
The exception that is thrown when a configuration system error has occurred.

The web.config file is exactly what I used when the app was created in asp.net 4.5.
I know that the Membership object uses the SQL membership database.

What should I change?

Thanks,

web.config:
=========
<connectionStrings>
    <remove name="MemberShipSQLConnectionString"/>
    <add name="MemberShipSQLConnectionString"
         connectionString="Initial Catalog=aspnetstockpro;
         Data Source=tcp:SQLB37.webcontrolcenter.com;
         User ID=Dovberman;Password=1088Delb!;connection timeout =30"
         providerName="System.Data.SqlClient"/>
    <add name="conStockSelect" connectionString="Initial Catalog=stockprosql; &#xD;&#xA; Data Source=tcp:SQLB37.webcontrolcenter.com; &#xD;&#xA; User ID=Dovberman;Password=1088Delb!;connection timeout =30"
         providerName="System.Data.SqlClient"/>
    <add name="StockSelectSQLConnectionString" connectionString="Initial Catalog=stockprosql; Data Source=tcp:SQLB37.webcontrolcenter.com; User ID=Dovberman; Password=1088Delb!; connection timeout =30"
         providerName="System.Data.SqlClient"/>
    <add name="conStockSelectLocal" connectionString="Initial Catalog=stockprosql;&#xD;&#xA; Data Source=PC-ADMIN  connection timeout =30"
         providerName="System.Data.SqlClient"/>
  </connectionStrings>

   <membership defaultProvider="DefaultMembershipProvider">
     
      <providers>
       
        <add name="SQLProvider" connectionStringName="MemberShipSQLConnectionString"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             applicationName="StockPro"
             requiresUniqueEmail="true"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             passwordAttemptWindow="10"
             minRequiredNonalphanumericCharacters="0"
             minRequiredPasswordLength="8"
             type="System.Web.Security.SqlMembershipProvider"/>
      </providers>
 
    </membership>

    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
        <add name="CustomizedRoleProvider"
        type="System.Web.Security.SqlRoleProvider"
        connectionStringName="MemberShipSQLConnectionString"
        applicationName="StockPro"/>
      </providers>
    </roleManager>

   <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
0
Comment
Question by:Dovberman
  • 2
2 Comments
 

Accepted Solution

by:
Dovberman earned 0 total points
Comment Utility
This fixed it:
Changed this:

 <membership defaultProvider="DefaultMembershipProvider">
     
      <providers>
       
        <add name="SQLProvider" connectionStringName="MemberShipSQLConnectionString"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             applicationName="StockPro"
             requiresUniqueEmail="true"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             passwordAttemptWindow="10"
             minRequiredNonalphanumericCharacters="0"
             minRequiredPasswordLength="8"
             type="System.Web.Security.SqlMembershipProvider"/>
      </providers>
 
    </membership>



To this:

   <membership defaultProvider="SQLProvider">

      <providers>
       
        <add name="SQLProvider"
             connectionStringName="MemberShipSQLConnectionString"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             applicationName="StockPro"
             requiresUniqueEmail="true"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             passwordAttemptWindow="10"
             minRequiredNonalphanumericCharacters="0"
             minRequiredPasswordLength="8"
             type="System.Web.Security.SqlMembershipProvider"/>
      </providers>
 
    </membership>
0
 

Author Closing Comment

by:Dovberman
Comment Utility
Sometimes one word makes a difference.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now