Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

URL Demo

0.00/5 (No votes)
20 Apr 2004 1  
How to create a web site that loads itself on multiple URLs.

Sample Image - URL_Demo.jpg

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.

  1. Create ASP.NET Web project.
  2. 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);

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here