Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same ASP.NET website on multiple subdomains but different databases?

Consider that I want to create 10 websites in IIS, each of them pointing to the same website on local hard drive, each one running the same code, but on different subdomain.

subdomain1.domain.com, subdomain2.domain.com, ..., subdomain10.domain.com

How can I add multiple connection strings in my web.config file and bind each connection string to a different subdomain ?

I want to do this because every website will have a different database with different data.

like image 267
Sorin Avatar asked Oct 10 '10 14:10

Sorin


People also ask

Can a website have multiple subdomains?

A subdomain is an additional part to your main domain name. Subdomains are created to organize and navigate to different sections of your website. You can create multiple subdomains or child domains on your main domain.

Is a subdomain a separate website?

A subdomain is very different from a subdirectory; it is like an entirely different website. The subdomain is associated with the domain, but not the website that is associated with the domain name. A subdomain is generally considered as a standalone site that is branched off from the main domain.

Can you stack subdomains?

Since subdomains effectively replace the domain and count as that domain for pretty much all purposes, and you can't take a subdomain and its domain together, you can't take both.

How do I share session state across subdomains?

To share session data (via browser cookies) across across subdomains, lets say Page on example.com and Page on example.com , you can declare the cookie's domain as ". Example Domain " which would allow both subdomains to read the session data.


1 Answers

Since the web.config file is common for all the sites, you can add multiple connection strings like this for each sub domain.

<connectionStrings>
        <add connectionString="" name="subdomain1"/>
            <add connectionString="" name="subdomain2"/>
</connectionStrings>

Then you can check for the current url using

HttpContext.Current.Request.Url.AbsoluteUri

and then use the correct connection string(?)

like image 159
Shoban Avatar answered Oct 21 '22 03:10

Shoban