Step 1: Add UrlRewriting Class in App_Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Web;
public class UrlRewriting : IHttpModule
{
public void Init(HttpApplication app)
{
app.BeginRequest += ppBeginRequest;
app.EndRequest += ppEndRequest;
}
public void Dispose()
{
}
public void ppBeginRequest(object s, EventArgs e)
{
HttpApplication app = default(HttpApplication);
string[] urlArr = null;
app = (HttpApplication)s;
string strHostDomain = app.Context.Request.ServerVariables["SERVER_NAME"];
urlArr = strHostDomain.Split('.');
if (urlArr.Length == 3)
{
if (urlArr[0].Substring(0, 3) == "www")
{
// do nothing here .. normal site
}
// Subdomain Blogs: http://blogs.mysite.com
if (urlArr[0].Substring(0, 3) == "blogs")
{
app.Context.RewritePath("/blogs/Default.aspx");
// app.Context.Request.Url.PathAndQuery = if you need the querystring
}
// Subdomain Blogs: http://photosite.mysite.com
if (urlArr[0].Substring(0, 3) == "photosite")
{
app.Context.RewritePath("/photosite/Default.aspx");
// app.Context.Request.Url.PathAndQuery = if you need the querystring
}
}
}
public void ppEndRequest(object s, EventArgs e)
{
}
}
Step 2: Add this part in web.config
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpModules>
<add name="UrlRewriting" type="UrlRewriting"/>
</httpModules>
</system.web>