Last post Jul 29, 2011 04:31 AM by Dave Sussman
Jul 28, 2011 05:33 AM|madhubms|LINK
Hi, We have 15 websites running exactly the same source code but with different connections to 15 DBs in th web.config.Since it is getting cumbersome to maintain, is it possible to have just one folder and multiple connections based on the URL.Our struture is like thisUnder Inetpub\wwwroot we have Site ASite BSite Ceach with its own web.config which connect to different DBs A, B and C etcwe use sitea.domain.com , siteb.domain.com etcI want to have a single source in the IIS but based on the URL, If Site A connect to DB A, If Site B connect to DB B etc.Is this possible.ThanksMadhu
Jul 28, 2011 06:03 AM|shashankgwl|LINK
I think you can use Application_BeginRequest and check the Request.Url property and then set the connectionstring value, which should be used throughout the application's lifetime.
protected void Application_BeginRequest(object sender, EventArgs e)
Application["ConStr"]="this connection string";
Jul 29, 2011 04:31 AM|Dave Sussman|LINK
I've done something similar in the past, but using convention, where the connection strings have the site name in them. Eg:
<add name="site1_cs" ... />
<add name="site2_cs" ... />
Then in your code:
Application["ConStr"] = Request.Url.Host + "_cs";
It might not be Host - I can't remember offhand which gives the right part of the domain.