Reputation: 167
I currently have a website for eg:- www.domain.com & i need to create 3-4 sub domains for this website like abc.domain.com,xyz.domain.com ...
I want to maintain the same codes for all the subdomains, & for each of the Sub domains i have the same look & feel except the css style, the logo's, the Page title's & few Page contents would be changing.
The titles & images(i will only store the image name) can come from the resource file,
Like for example i will have Resource file for each sub domains & my website should automatically pick the resource file based on the domain.
but not sure which is the best & easy way to achieve this.
Similar Question I have Seen based on UI Culture. I donot want to follow this approach. As i will be using English for all my subdomains & in future i will be having more sub domains.
Upvotes: 0
Views: 769
Reputation: 14860
If you have full-control over your web server and you are using IIS, you can achieve this easily by having multiple sites pointing to the same physical location in the file system. Then, each site can (and must) have a unique binding which will allow IIS to route incoming request to the appropriate site (sub-domain). Note that it is important that you have each site running on its own app pool rather than sharing the same app pool
Furthermore, you need to consider that the scalability of this approach is very limited, if in the future you need to have...say, hundreds of sites it can potentially add a lot of overhead to your web server. So, if you need a scalable solution you should go for a multi-tenant approach instead which you can easily load-balance.
One last note, images bundled up in resource files is a pretty bad idea...avoid it!!!
Having different sites pointing to the same physical location doesn't mean that they have to share the same content all the time. You can still decide what content to serve dynamically based on the request context by simply inspecting the request object...this goes for dynamic ASP.NET pages, however for static pages you will need to create a virtual directory for each site and point them a location specific to that site only...this will allow you to customize the content for a specific site...see screenshot below how I have a "login" virtual directory which points to somewhere else...
This is a very simplistic example. Suppose you have two sites set up...
The sites are pointing to the same physical location...C:\inetpub\domain\site
Then, there's a page index.aspx
that has a panel in it that displays a welcome message...
<asp:Panel ID="pnlWelcome" runat="server"></asp:Panel>
for the "en" sub-domain you want to display "Welcome to Our Site" in english but for the "es" sub-domain you want to display "Bienvenidos a Nuestro Sitio" in spanish.
Then, if you set up a virtual directory for each site pointing to a separate location in the file system....say for the "en" domain the location is...C:\sitescontent\en\
and for the "es" domain the location is ...C:\sitescontent\es\
, you can then place a user control, xml file, whatever you need inside these site-specific folders with the site-specific content. Then it is as easy as referencing the site-specific content with a virtual path...
string path = MapPath("~/content/{your_site_specific_content}");
or
Control ctrl = LoadControl("~/content/{your_site_specific_content}");
pnlWelcome.Controls.Clear();
pnlWelcome.Controls.Add(ctrl);
If you have a more complex architecture in your application, you would want to inspect the Request
object to find out in which context the request is executing whether in the "en" site context or "es" site context....
HttpContext.Current.Request.Url.Host;
By NO means, I'm suggesting this the best way to handle localized resources in your system...it is just an example of how to handle site-specific content.
Upvotes: 1