locked
Multiple sites under same directory RRS feed

  • Question

  • User-1139942089 posted
    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 this

    Under Inetpub\wwwroot we have
    Site A
    Site B
    Site C

    each with its own web.config which connect to different DBs A, B and C etc

    we use sitea.domain.com , siteb.domain.com etc
    I 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.

    Thanks
    Madhu
    Thursday, July 28, 2011 5:33 AM

Answers

  • User-1856974186 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 29, 2011 4:31 AM

All replies

  • User377791177 posted

    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)
            {
                if(Request.Url.PathAndQuery.Contains("somevalue")
                    Application["ConStr"]="this connection string";
            }
    Thursday, July 28, 2011 6:03 AM
  • User-1856974186 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 29, 2011 4:31 AM