Searching for flexible way to specify conenction string used by APS.NET membership

Posted by bzamfir on Stack Overflow See other posts from Stack Overflow or by bzamfir
Published on 2010-03-17T08:27:00Z Indexed on 2010/03/17 8:31 UTC
Read the original article Hit count: 556

Hi,

I develop an asp.net web application and I use ASP.NET membership provider. The application uses the membership schema and all required objects inside main application database However, during development I have to switch to various databases, for different development and testing scenarios. For this I have an external connection strings section file and also an external appsettings section, which allow me to not change main web.config but switch the db easily, by changing setting only in appsettings section.

My files are as below:

<connectionStrings configSource="connections.config">
</connectionStrings>

<appSettings file="local.config">
    ....

ConnectionStrings looks as usual:

<connectionStrings>
  <add name="MyDB1" connectionString="..." ... />
  <add name="MyDB2" connectionString="..." ... />
  ....
</connectionStrings>

And local.config as below

<appSettings>
    <add key="ConnectionString" value="MyDB2" />

My code takes into account to use this connection string

But membership settings in web.config contains the connection string name directly into the setting, like

<add name="MembershipProvider" connectionStringName="MyDB2" ...>
....
<add name="RoleProvider" connectionStringName="MyDB2" ...>

Because of this, every time I have to edit them too to use the new db.

Is there any way to config membership provider to use an appsetting to select db connection for membership db? Or to "redirect" it to read connection setting from somewhere else? Or at least to have this in some external file (like local.config)

Maybe is some easy way to wrap asp.net membership provider intio my own provider which will just read connection string from where I want and pass it to original membership provider, and then just delegate the whole membership functionality to asp.net membership provider.

Thanks.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-membership