Paste this into the new .cs file in the App_Code folder:
using System; using System.Web; public class TestModule : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); } void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; if (app.Request.Url.Host == "example.com") { app.Response.Status = "301 Moved Permanently"; app.Response.AddHeader("Location", "http://www.testdomain.com/Some.aspx"); } } public void Dispose() { } }
Then add this to your web.config in system.web:
<httpModules> <add type="TestModule" name="TestModule" /> </httpModules>
source share