Supporting multiple hosts within one ASP.NET application

You may have seen the website in the guise of www.dotnetkicks.com, but it also can be viewed from the following domains: www.kick.ie, www.javakicks.com & www.mozillakicks.com. All of these hosts are mapped to the same ASP.NET application in IIS. This has a number of benefits:

- Reduced memory footprint - there is only one IIS application running for all four hosts
- Shared cache - As the AppDomain is the same for all four websites, the cache is shared
- Ease of deployment and maintenance - we are only dealing with one deployed application. Creating new sites on new hosts is also a snap - simply add the domain mapping in IIS and add a new row in the Host table in the database

The mapping from domain to application is achieved in IIS (you can test this on your development machine by adding a few host entries in your system32\drivers\etc\hosts file):

A Host table in our database defines a number of properties of each host including the MasterPage & Theme to use (currently all sites are using the same MasterPage) and whether to show ads or not. The host information is cached in memory for quick access and this cache is accessed early in the lifecycle of each incoming page request, allowing the resulting response to be customised for the host of the request.

Any subsequent calls to the Data Access Layer will include the HostID of the current request, allowing us to tailor the data for the specific host. You can see this by using your www.dotnetkicks.com login on the other sites too.

Published Wednesday, January 25, 2006 4:50 PM by gavinjoyce

Comments

# re: Part I - Supporting multiple hosts within one ASP.NET application

Wednesday, January 25, 2006 12:05 PM by dotnetkicks.com trackback

# re: Part I - Supporting multiple hosts within one ASP.NET application

And each of these domains will have to have their DNS A record in their zone file pointing to the website's bound IP address.

Wednesday, January 25, 2006 12:12 PM by Wim Hollebrandse

# re: Part I - Supporting multiple hosts within one ASP.NET application

That's correct Wim, thanks for adding that.

If you ping dotnetkicks.com, javakicks.com, mozillakicks.com and kick.ie, you will see that they all have the same IP address.

Wednesday, January 25, 2006 12:19 PM by Gavin Joyce

# re: Part I - Supporting multiple hosts within one ASP.NET application

Just remember....that the simplest solution if you can dedicate an IP address for any hosts pointing at the site, is just to have a single entry in IIS containing your IP address, and leave the HOST field blank.

This is much easier than adding a new entry to IIS each time you want to add a new virtual host.

We do this to host thousands of domain names on IIS 6 and ASP.NET 2.0

The only reason to do what you have shown above is if you have more than one website running from a single ip address.

Wednesday, January 25, 2006 1:14 PM by David Taylor

# re: Part I - Supporting multiple hosts within one ASP.NET application

Thanks for adding that David.

In my case I will be hosting multiple applications on the one IP address, so I do specify the various host mappings for this application.

Wednesday, January 25, 2006 1:18 PM by Gavin Joyce

# re: Part I - Supporting multiple hosts within one ASP.NET application

You just got dugg!

Friday, January 27, 2006 2:46 PM by Diesel

# re: Supporting multiple hosts within one ASP.NET application

Is your code open source?

Tuesday, January 31, 2006 9:35 AM by James

# re: Supporting multiple hosts within one ASP.NET application

Sorry James, this project is closed source.

Tuesday, January 31, 2006 9:54 AM by Gavin Joyce

# Good site

http://buyvaliumm.blogcu.com buy valium

<a href="http://buyvaliumm.blogcu.com">buy valium</a>

[url=http://buyvaliumm.blogcu.com]buy valium[/url]

Thursday, May 03, 2007 11:28 PM by konan

# re: Supporting multiple hosts within one ASP.NET application

Is there a limit to how many entries that can be added in this way? David's solution seems to bypass any limitations that may exist, but it would still be good to know.

Thanks for the article!

Olja

Thursday, May 24, 2007 2:32 PM by Olja

# re: Supporting multiple hosts within one ASP.NET application

How does session work across these sites? if you have more than one site open at the same time do they share a single session?

Wednesday, October 17, 2007 9:12 AM by Peter Hunter

# top results only

The bigger the search engine the longer to get what you want...try something more direct!

Thursday, July 10, 2008 8:12 PM by top results only

# Avandia.

Avandia drug_monograph. Avandia. How does avandia work.

Wednesday, July 30, 2008 8:26 AM by Avandia side effects.

Leave a Comment

(required) 
(required) 
(optional)
(required)