Click here to Skip to main content
15,885,009 members
Articles / Web Development / ASP.NET
Article

URL Demo

Rate me:
Please Sign up or sign in to vote.
1.00/5 (10 votes)
20 Apr 20041 min read 132.9K   1.2K   20   5
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:

C#
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:

C#
string domainName = Request.Url.Host.ToLower();

Check if alias was given in the query string.

C#
if (Request.Params["Alias"]!=null)
portalAlias = Request.QueryString["Alias"];

Return alias + Domain name if alias was given, otherwise return only domain name.

C#
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:

C#
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...

C#
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


Written By
Business Analyst Valentia Technologies
Ireland Ireland
Mubi
^^^^^^^^^^^^^^^^^^^^^^^
www.mrmubi.com

Comments and Discussions

 
QuestionURL REDIRECTION Pin
Member 917112831-Jul-12 20:16
Member 917112831-Jul-12 20:16 
AnswerDoesn't work in dev Pin
meaningoflights10-Apr-08 18:39
meaningoflights10-Apr-08 18:39 
Generalwindow.location.hash Pin
yunusayd6-Oct-07 1:01
yunusayd6-Oct-07 1:01 
Generaltanx Pin
Mahsa Hassankashi10-Aug-07 2:15
Mahsa Hassankashi10-Aug-07 2:15 
General:cool:Thanks for the simple solution. Pin
rtett21-Apr-05 7:20
rtett21-Apr-05 7:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.