Tutorials » AspNet tutorials »

How to host multiple web sites under one shared hosting account?

Learn how to host multiple website under one shared hosting account.

Typically, when you register an account for a shared hosting plan, you will be allowed to create one site. However, if they allow you to use more than one domain name for your account, you can create multiple web sites under one account.

The first thing you have to do is, under your root folder, create separate folders for each of the web sites you want to host. Using the control panel provided by the hosting service, add all the required domain names to your account.

Now, put one file called "default.aspx" into the root folder. Add some code to find out the domain name from the requests and redirect the request to appropriate folder based on the domain name.

For example, assume you need to host 2 different web sites called http://aspspider.com and http://dotnetspider.com.

Create 2 folders with the names "aspspider" and "dotnetspider" in your root. Add the following code into the default.aspx file in the root:

Dim siteName As String = Request.ServerVariables("SERVER_NAME").ToString().ToLower()
If siteName = "aspspider.com" Then
Else If siteName = "dotnetspider.com" Then
' Error !
End If

How it works ?

If you have configured your domain names correctly, when anybody type the domain names, the request will come to your web site and it will try to load the default web page. In the above example, whether you type http://www.aspspider.com or http://www.dotnetspider.com, the same default.aspx page in the root will be loaded.

What we have done in the default page is, we will identify the domain name from the request and redirect to another folder based on the name. In the above case, we have to make sure that all files for the site aspspider.com is under the folder "asppsider" and all files for the site dotnetspider.com is under the folder "dotnetspider".


The above approach will work great in most of the cases. However, let us assume that some one know that you have hosted multiple web sites using the above approach. He can type the URL http://www.aspspider.com/dotnetspider. In this case, he is going to see the site "www.dotnetspider.com" because the URL is directly accessing the dotnetspider folder.

The above URLs are just an example. The sites www.dotnetspider.com and www.aspspider.com are hosted as separate web sites. Even if you type folder names as shown above, you cannot access the content of the other site.

If you are looking for free web hosting, try AspSpider.NET.

Next Chapter: Download Visual Web Developer 2005 Express Edition
Previous Chapter: Shared hosting or dedicated hosting - which one to choose ?
More Chapters: ASP.NET Tutorials
More Tutorials: Tutorial Index

Top Contributors
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India