301 redirect "/Default.aspx" to "/" Root Asp.Net

Sunday, October 30, 2011

Question : How to use global.asax and do 301 redirect "/Default.aspx" to "/" Root ?
Answer :

Add below code in global.asax, thats it.

void Application_BeginRequest(object sender, EventArgs e)
        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://induway.com"))
            HttpContext.Current.Response.Status = "301 Moved Permanently";
            HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://induway.com/default.aspx", "http://www.induway.com"));

Let me know, if you have any query..

Thanks Hope this post will help you, if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Email: raj143svmit@gmail.com
Dobazaar (Dubai, UAE)

1 comment :

Kevin Leinen said...

Hi It's very informative posting. Thanks for sharing.

.Net Development