Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving asp.net membership web.config settings to Database Is this even possible?

I am hoping for fruitful answer to this. How should i move the settings provided in web.config for asp.net membership into a database for cross application customization. For example membership information include below

  <providers>
    <add 
      name="OdbcProvider" 
      type="Samples.AspNet.Membership.OdbcMembershipProvider" 
      connectionStringName="OdbcServices"
      enablePasswordRetrieval="true"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="true" 
      writeExceptionsToEventLog="true" />
  </providers>
</membership>

Extra

.NET 2.0

ASP.NET 2.0

Related

moving asp.net membership specific settings to a separate config file

like image 388
Deeptechtons Avatar asked Oct 10 '22 09:10

Deeptechtons


1 Answers

Yes, you can! We have done this successfully.

You can do it in a few ways, one is to inject whichever properties you need into an instance of the provider (this example assumes you are using SqlMembershipProvider and shows how you can inject the connection string, but you can take a look at the source of OdbcMembershipProvider to get an idea where to do this yourself):

public static void InjectConnectionStringIntoSqlMembershipProvider(SqlMembershipProvider provider, string connectionString) {
    Type t = typeof(SqlMembershipProvider);
    FieldInfo fi = t.GetField("_sqlConnectionString", BindingFlags.NonPublic | BindingFlags.Instance);
    if (fi == null) throw new InvalidOperationException("Invalid private identifier.");
    fi.SetValue(provider, connectionString);
}

Or, you can create your own provider by creating a class that inherits MembershipProvider.

Or, as the link from @Andomar suggests, you can inherit from any implementation of MembershipProvider (such as SqlMembershipProvider, amongst others), to get what you want.

We have done all three over the years depending on how much customisation was required.

like image 121
enashnash Avatar answered Oct 13 '22 10:10

enashnash