
Introduction
Some times, you have to serve one website for multiple URLs. For example: you might have many domain names:
And all these requests will be redirected to the site which is hosted at http://www.google.com/. Now, web site residing at www.google.com must be so generic that it detects the URL and applies regional settings. I.e., if request is for www.google.com.pk, then load it only for all users @ google.com.pk, and apply all other contents of google.com.pk.
You can do all this only if you can detect the URL of the request.
How to do that:
I will explain to you how to do that using ASP.NET.
- Create ASP.NET Web project.
- Add a class URLClass.cs.
Add following function to the class:
public string GetDom(System.Web.HttpRequest Request)
In the Request
parameter of this function, you get all the variables of the request. Now, get the request URL.
To get domain name, write this code:
string domainName = Request.Url.Host.ToLower();
Check if alias was given in the query string.
if (Request.Params["Alias"]!=null)
portalAlias = Request.QueryString["Alias"];
Return alias + Domain name if alias was given, otherwise return only domain name.
if (portalAlias==""){return
(domainName);}
else{return(portalAlias+"."+domainName);}
Using the Class:
Open WebForm1.aspx code-behind file. Write following code:
Create instance of the class:
URLClass cls = new URLClass();
string DomainName=cls.GetDom(Request);
this.Label1.Text =DomainName;
Now place your code here in which you want to load settings for requested site.
For example...
ApplySettingOfDomain(DomainName);