PHONE 1300 138 046  Australian Owned and Operated  All prices in Australian Dollars

Knowledgebase

Portal Home > Knowledgebase > Windows clients > ASP.NET > 301 redirect using global.asax.cs

301 redirect using global.asax.cs


Below is code to do 301 redirect using the global.asax.cs file.



       protected void Application_BeginRequest(object sender, EventArgs e)

       {

              string s1 = "http://somedomainname.com.au";

              string sRedirect = "http://www.somedomainname.com.au";

              if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(s1))

              {

                     string sNewPage = Request.Url.ToString().ToLower().Replace(s1, sRedirect);

                     Response.Clear();

                     Response.Status = "301 Moved Permanently";

                     Response.AddHeader("Location", sNewPage);

                     Response.End();

              }

              THEN REPEAT FOR EACH REDIRECT YOU WANT TO CREATE

       }

 

Was this answer helpful?

Add to Favourites Add to Favourites Print this Article Print this Article

Also Read