I'm going to refer to the MVC startup example that comes with Visual Studio 2008 for simplicity. Its the sample application that has the Account and Home controllors using the AccountModels.cs.
I would like to modify the application so that on the user login screen, the user must enter a User name, Password and Selection from a drop down box. This selection option will determine which connectionString the application will use for Membership and
Roles.
My web.config file would look something like this:
I would also like to have it so if the user clicks on "remember me" at login, it will also remember their role information so that my controllers could still user the [Authorize] filters.
solidfish
Member
37 Points
32 Posts
Supporting multiple connectionStrings for Memberships and Roles based on User Login
Mar 01, 2012 11:12 PM|LINK
I'm going to refer to the MVC startup example that comes with Visual Studio 2008 for simplicity. Its the sample application that has the Account and Home controllors using the AccountModels.cs.
I would like to modify the application so that on the user login screen, the user must enter a User name, Password and Selection from a drop down box. This selection option will determine which connectionString the application will use for Membership and Roles.
My web.config file would look something like this:
<connectionStrings> <add name="optionA" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdbA.mdf;User Instance=true" providerName="System.Data.SqlClient"/> <add name="optionB" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdbB.mdf;User Instance=true" providerName="System.Data.SqlClient"/> <add name="optionC" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdbC.mdf;User Instance=true" providerName="System.Data.SqlClient"/> <add name="optionD" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdbD.mdf;User Instance=true" providerName="System.Data.SqlClient"/> </connectionStrings>And my RoleProvider would look something like this:
<roleManager enabled="true" defaultProvider="optA" cacheRolesInCookie="true" createPersistentCookie="true" cookieProtection="All"> <providers> <clear /> <add name="optA" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="optionA" applicationName="test" /> <add name="optB" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="optionB" applicationName="test" /> <add name="optC" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="optionC" applicationName="test" /> <add name="optD" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="optionD" applicationName="test" /> </providers> </roleManager>I would also like to have it so if the user clicks on "remember me" at login, it will also remember their role information so that my controllers could still user the [Authorize] filters.
Thank you for your help!