Follow in Twitter & Facebook



Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Saturday, February 18, 2012

Redirect from domain.com to www.domain.com asp.net

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://sharepointdotnet.com";

        string ToHomeURL = "http://www.sharepointdotnet.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));

        }
}

You can also check a good article on Page Lifecycle Events in ASP.Net.




0 on: "Redirect from domain.com to www.domain.com asp.net"