Supporting two domains in one ASP.NET MVC site – A Poor Man’s Approach

Hosting Two Different Domains in Same ASP.NET MVC Site

Motivation – I am Cheap!

I have a hosting account at DiscountASP.NET that I have used as a playground for anything I want to host on the web. My personal Coding Out Loud site is hosted there (with a few directories that are not linked, for example). Since starting the Boston Azure User Group, I need a place to host a page. While I would eventually like to host the user group site on Azure itself, for now I have produced a simple ASP.NET MVC site. To avoid paying for two hosting accounts, I am reusing my existing account – sharing the hosting across and – but still maintaining their distinct identities.

We can consider the Boston Azure User Group the main site, and Coding Out Loud the secondary site.


The approach I take makes sense to me since I want a solution that is:

  • Very simple
  • Inexpensive
  • Easy to manage once implemented
  • Treats as the main site, but “tolerates” being around (in other words, maintainability/risk of errors for is less important)


In order to host two sites with a single hosting account, you have a few steps:

  1. Add a Domain Pointer with your ISP. If, like me, your site is hosted on a shared IP address, this step is necessary so that the site’s IIS web server knows which top-level directory your domain is associated with. In my case, this tells both and to go to the same site.
  2. Configure your DNS. This is easier than it sounds. Your ISP will tell which DNS servers your should point to. You could also deal with Godaddy’s Domain Forwarding and cloaking, but for a one-time cost of $15 with my ISP (DiscountASP.NET) I just added the pointer – a cleaner solution, and possible more search-engine-friendly.
  3. Note that the following changes to the code are only necessary if you want different results dependent on which domain is used to access the site – in other words, I don’t want my visitors to be stumbling across any artifacts, and vice versa. The following screen shot includes the hack simple code modifications – they are circled – a private method with a little dirty work, invoke the method in the right place, and display a specific View. Note that the view is specified in a different file – and under a folder that is specific to your secondary site – CodingOutLoud in my case.

Poor Man's Domain sharing in ASP.NET MVC

To create the …/Views/CodingOutLoud/Index.aspx view shown in the right-hand pane in the screen shown above, you would do the following:

  1. Right-Click on Views folder and choose Add > New Folder from the pop-up. I called mine “CodingOutLoud” and it is shown above.
  2. Right-Click on the newly created Views/CodingOutLoud folder, this time choose Add > View… from the pop-up, as shown below. I called my View “Index” (and since it lives under CodingOutLoud folder it does not clash with other Views with that name, given the default routing rules).


Name your view – and I also chose not to use the master page, so I unchecked it:


Once created, …/Views/CodingOutLoud/Index.aspx can contain any code you like – even plain old HTML.

This is all it took to get this simple approach to work. Now when users visit via “” they are diverted to …/Views/CodingOutLoud/Index.aspx, and otherwise the usual machinery of ASP.NET MVC takes over.

Other Potential Approaches

I considered, but did not adopt, some other approaches – mostly since I wanted to do something very simple. Here are some of the other approaches:


4 thoughts on “Supporting two domains in one ASP.NET MVC site – A Poor Man’s Approach

  1. Pingback: ASP.NET MVC Archived Blog Posts, Page 1

  2. Marti

    Thank you for every other excellent post. The place else may
    anybody get that type of information in such a perfect way
    of writing? I’ve a presentation next week, and I am on the search for such info.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.