Click here to Skip to main content
15,947,389 members
Please Sign up or sign in to vote.
4.43/5 (3 votes)
See more:
I've URLs in my website and which are using query string values For example:

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

I've IIS 7.5 installed on server machine and using 4.0.
Updated 2-Apr-16 2:03am

1 solution

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
       RewritePath(HttpContext.Current.Request.Path + SubDomain + "/", false);  

// from :
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;
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900