I'm going to have several sub-domains point to an asp.net website application. After detecting the originating sub-domain (a separate question), I need to use that sub-domain name to modify a site connectionstring to point to a different database (one database per sub-domain.)
This has to happen in the Page_Load method of a login page that uses the aspnet_Membership login control. That is, I need to reset the connection string to point to the correct DB before the login control can operate.
I've seen a couple suggested methods for modifying connection strings however, I'm not clear on which one to use.
I tried the code below, however, the second response.write, which should show the result, shows no change. However, maybe I'm re-reading the original unchanged value.
Dim wrkNewConnStr As String
wrkNewConnStr = "Data Source=localhost; Initial Catalog=test01;"
wrkNewConnStr = wrkNewConnStr & " User ID=testuser1; Password=testuserpw1"
Dim config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
'Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim connectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
Response.Write("1 - " & connectionStringsSection.ConnectionStrings("TestDB1ConnectionString").ConnectionString)
Dim wrkOrigConnStr As String
wrkOrigConnStr = connectionStringsSection.ConnectionStrings("TestDB1ConnectionString").ConnectionString
wrkOrigConnStr = wrkNewConnStr
Response.Write("2 - " & connectionStringsSection.ConnectionStrings("TestDB1ConnectionString").ConnectionString)
It seems like any such modification to a connection string would need to take place in memory, not on disk, since many users could be accessing the main site from several sub-domains. However, I would appreciate pointers to something that spells that out explicitly, so I can understand it better.
> How to dynamically change a connection string at the initial load of a membership login page
> How does that only affect memory and not disk