2 or More Domain Names Linked to the Same Folder
Most if not all web hosting services allow users to link two or more domain names to the same account to save them the cost of a new account for each domain name. With such accounts, opening any of the registered domain names calls the same default page as the other. The solution is to write a Response.Redirect() call in the default page (usually Default.aspx) to redirect the user depending on the domain name entered.
The server variable SERVER_NAME contains the domain name part of the URL, so if the user entered ‘http://example.com/folder1/default.aspx’ its content will be ‘example.com’, and if the user entered ‘http://www.example.com/folder1/default.aspx’ its content will be ‘www.example.com’. To check for both versions always use the String object’s Contains() method, instead of checking for equality.
protected void Page_Load(object sender, EventArgs e)
{
string domainName = Request.ServerVariables["SERVER_NAME"].ToString();
domainName = domainName.ToLower();
if (domainName.Contains("example.com"))
{
Response.Redirect("~/dotcom.aspx");
}
if (domainName.Contains("example.net"))
{
Response.Redirect("~/dotnet.aspx");
}
}
Amged Rustom ASP.NET · MONO 2.0