Saturday, March 31, 2012

Sharing Same Files Across Different URLs

Hi,

I'd like to build a web application (let's say the domain name is "http://www.wxyz.com") for car salesmen to use. They'll come and register, and a site will be created for each of them with URL's like "http://JOHN.wxyz.com" and "http://JANE.wxyz.com". They all share the same set of physical .aspx & .cs files and the one database etc, but when the site is loaded, I need to be able to detect from the URL which sales person's data to query.

I would prefer not to pass along the sales person's name in the querystring (like "http://www.wxyz.com/index.aspx?id=john").

How can this be done?


Thanks,
ywb

You can read the raw url: (C# syntax)
string rawURL = HTTPContext.Current.Request.RawUrl;

Now you can use string manipulation to read in the string:
string rawURL = HttpContext.Current.Request.RawUrl;
rawURL = rawURL .Substring(7); //<--Make sure this won't change (https and http will have different start indices)
string[] splitURL = rawURL .Split(".");

You'll find your name insplitURL[0].


HionSlaught,

Thanks for the advice.

How about on the IIS? How do I set up each addtional site? Is there any way to automate this?

ywb.


Not sure how to automate it, but you can just have one page that handles who logged in and their content. Then use URL rewriting to "show" john.site.com instead of the default name. That's just one idea.

0 comments:

Post a Comment