301 redirect using global.asax.cs


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



       protected void Application_BeginRequest(object sender, EventArgs e)

       {

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

              string sRedirect = "http://yourredirecteddomainname.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

       }

  • 29 Users Found This Useful
Was this answer helpful?

Related Articles

How to create a Virtual Directory

How to create a Virtual Directory (Application for Asp.net) If you need asp.net to...

How to use the session state server (Sessions issues)

If you are having problems loosing sessions please use the session state server. (ASP.NET only)...

Cross-Site Scripting in ASP.NET

Cross-Site Scripting in ASP.NET Cross-site scripting attacks exploit vulnerabilities in Web page...

How to change DOT NET Version (Site level)

Login to your control panel at http://control.apexhost.net.au Please note: Ensure you set your...

Redirect old .asp or any non aspx pages using 404

Add this to the System Webserver section in the web.config file to handle any non .aspx...