Click here to Skip to main content
13,631,100 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I've URLs in my website and which are using query string values For example:

http://foo.com/xyzPage.aspx?barvalue=yehaa
to
http://yehaa.foo.com/

Please suggest how it can be accomplished without actually creating subdomains on server ..

I've IIS 7.5 installed on server machine and using Asp.net 4.0.
Posted 16-Jan-14 1:29am
Updated 2-Apr-16 2:03am
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

protected void Application_BeginRequest(Object sender, EventArgs e)
{   
    var SubDomain = GetSubDomain(HttpContext.Current.Request.Host);
    // this is a simple example, you can place your variables base on subdomain
    if(!String.IsNullOrEmpty(SubDomain))
       RewritePath(HttpContext.Current.Request.Path + SubDomain + "/", false);  
}

// from : http://madskristensen.net/post/Retrieve-the-subdomain-from-a-URL-in-C.aspx
private static string GetSubDomain(Uri url)
{
  string host = url.Host;
  if (host.Split('.').Length > 1)
  {
    int index = host.IndexOf(".");
    return host.Substring(0, index);
  }

  return null;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.180712.1 | Last Updated 2 Apr 2016
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100