Community Support & Help Center for Hosting, Dedicated Services, Colocation, Design & Development
Hosting, Dedicated Services, Colocation, Design & Development

Proper asp.net 301 Redirect Script (Moved Permanently) for domains using IIS & asp.net C#

rated by 0 users
This post has 0 Replies | 1 Follower

Top 10 Contributor
Male
Posts 242
Shawn Hyde Posted: 03-27-2009 3:25 PM

In your global.asax file add the following code (edit bold areas):

<script language="C#" runat="server">
// This code is free as long as this line stays in tact. ©Code Shawn Hyde http://shawnhyde.com
protected void Application_BeginRequest(Object sender, EventArgs e)
        { 
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://olddomain.tld"))
{
    HttpContext.Current.Response.Status = "301 Moved Permanently";
    HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://olddomain.tld","http://newdomain.tld"));
}
}
</script>

Page 1 of 1 (1 items) | RSS
©1998-2009 · Area51 Computers/Services, all rights reserved.