Click here to Skip to main content
Licence 
First Posted 20 Apr 2004
Views 84,198
Bookmarked 19 times

URL Demo

By | 20 Apr 2004 | Article
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

About the Author

Mubi | www.mrmubi.com

Business Analyst
Valentia Technologies
Ireland Ireland

Member

Follow on Twitter Follow on Twitter
Mubi
^^^^^^^^^^^^^^^^^^^^^^^
www.mubshir.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
AnswerDoesn't work in dev Pinmembermeaningoflights18:39 10 Apr '08  
Generalwindow.location.hash Pinmemberyunusayd1:01 6 Oct '07  
Generaltanx Pinmembermahsa_kashi2:15 10 Aug '07  
Questionhttp://alfa-romeo.tangoing.info/ Pinsusshttp://alfa-romeo.tangoing.info/2:21 4 Dec '07  
Answerhttp://scrub-cap-patterns.tangoing.info/ Pinsusshttp://scrub-cap-patterns.tangoing.info/2:24 4 Dec '07  
General:cool:Thanks for the simple solution. Pinmemberrtett7:20 21 Apr '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 21 Apr 2004
Article Copyright 2004 by Mubi | www.mrmubi.com
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid