views:

167

answers:

2

I had an application that hooked onto 1 single database.

The app now needs to hook into multiple databases. What we want to do is, using the same application/domain/hostname/virtual dir give the user the option on the login screen to select the "App/Database" they want to connect into.

Each database has the App tables/data/procs/etc as well as the aspnet membership/roles stuff.

When the user enters the username/password and selects (select list) the application, I want to validate the user against the selected applications database.

Presently the database connection string for membership services is saved in the web.config. Is there any way I can override this at login time? Also, I need the "remember me" function to work smoothly as well. How does this work when the user comes back to the app in 5 hours... This process should be able to identify the user and application and log in appropriately.

+1  A: 

The only way possible is to change the conn string via reflection:

// Set private property of Membership provider.FieldInfo connectionStringField 
= GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
        connectionStringField.SetValue(this, connectionString);

Found here: http://forums.asp.net/p/997608/2209437.aspx

Why not just implement your own membershipprovider? Very easy to do and then you have full control of whats happening. I'm sure you'll come up with another custom scenario the default provider doesn't work well with.

AFAIK the remember me function should work exactly how your describing as long as the user doesn't delete their cookies.

jfar
A: 

Below is a link to an example using multiple connection strings for your membership providers.

ASP.NET Forum - Multiple Providers

Tommy