February 21, 2012 07:35 by
Scott
If you want to redirect from domain.com to www.domain.com in asp.net application, then you can do it through IIS settings, but you can do it through code file also. You can write the code in the global.asax file in the Application_BeginRequest method.
void Application_BeginRequest(object sender, EventArgs e)
{
string FromHomeURL = "http://yourdomain.com";
string ToHomeURL = "http://www.yourdomain.com";
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(FromHomeURL))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
Request.Url.ToString().ToLower().Replace(FromHomeURL, ToHomeURL));
}
}