5

In an ASP.net web application I have defined the following Membership provider in the web.config:

<membership>
  <providers>
    <add connectionStringName="MyServer" name="MyServer" type="System.Web.Security.SqlMembershipProvider" 
      enablePasswordReset="true" 
      requiresQuestionAndAnswer="false" 
      enablePasswordRetrieval="false" />
  </providers>
</membership>

When I run the application in the debugger, the property Membership.Provider.RequiresQuestionAndAnswer is true.

Why? And how can I fix this?

Update: Ar tuntime, the Membership.Providers collection contains two instances of Provider that are almost identical. The differences are:

  • The first Provider has Name=="AspNetSqlMembershipProvider" and RequiresQuestionAndAnswer==true
  • The second Provider has Name=="MyServer" and RequiresQuestionAndAnswer==false.

Now trying to figure out where the first one is coming from.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
urig
  • 16,016
  • 26
  • 115
  • 184
  • 2
    Does the provider name in the debugger match the name of your provider ("MyServer")? – Meidan Alon May 28 '15 at 09:30
  • @MeidanAlon the provider name in the debugger seems to be "AspNetSqlMembershipProvider". At the same time, it's showing the correct SQL connection string so it looks like it's the right one. – urig May 28 '15 at 11:07
  • That's weird, I'd try adding defaultProvider="MyServer" inside membership and to – Meidan Alon May 28 '15 at 11:15
  • @MeidanAlon Adding before the causes a ConfigurationErrorsException. Setting defaultProvider="MyServer" on did the trick. Thank you. Would you like to post this as an answer? Also - the question remains why there are two Providers instances. – urig May 28 '15 at 11:38

2 Answers2

3

Per the follow up question, the mystery providers is defined on a lower level config file, named machine.config, which is the server-wide parent config file for all asp.net sites running on the machine. See some more details at the MSDN page for asp.net config hierarchy.

Ken Egozi
  • 1,825
  • 11
  • 14
0

The fix for my problem is to specify in web.config:

<membership defaultProvider="MyServer>

The reason why there's an "extra" Provider at run-time is that it's defined in my machine.config file. Here's how to find yours.

Credit for fix goes to @meidan-alon and credit for root cause goes to @ken-egozi :)

Community
  • 1
  • 1
urig
  • 16,016
  • 26
  • 115
  • 184