Just open the web.config and edit the appsetting newSite with your new site. That’s all!
All the requests will be forwarded with “301 Moved Permanently” status code.
Example: Your site is published at http://www.currentsite.com and you want to redirect at http://www.newsite.com
upload the files at http://www.currentsite.com and edit the web.config like:
<appSettings> <add key="newSite" value="<strong>www.newsite.com</strong>"/> </appSettings>
All request will be forwarded like:
http://www.currentsite.com
-> http://www.newsite.com
http://www.currentsite.com/helloworld
-> http://www.newsite.com/helloworld
The site is tested on iis7, framework 4 Integrated pipeline mode (standard configuration in most of cases).
Source Code:
——————————— Web.config
<?xml version="1.0"?> <configuration> <appSettings> <add key="newSite" value="www.google.com"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0" /> <httpModules> <add type="Redirect.Module" name="Module" /> </httpModules> </system.web> <system.webServer> <modules> <add type="Redirect.Module" name="Module" /> </modules> </system.webServer> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
——————————— Module.cs
using System;
using System.Web;
using System.Configuration;
namespace Redirect
{
public class Module : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
context.EndRequest += (new EventHandler(Application_EndRequest));
}
private void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication hap = (HttpApplication)source;
HttpContext hc = (HttpContext)hap.Context;
string newSite = ConfigurationManager.AppSettings["newSite"];
string strUrl = newSite + hc.Request.Url.PathAndQuery;
hc.Response.Clear();
hc.Response.Status = "301 Moved Permanently";
hc.Response.Headers.Add("Location", strUrl);
}
private void Application_EndRequest(Object source, EventArgs e)
{
}
}
}




Gpx reducer:








“, “PlayStation”, “PlayStation Network”, “PlayStation Store”, “PlayStation Home”, “PS3″, “PSP”, “PS2″ and “
” are registered trademarks of Sony Computer Entertainment Inc. All titles, content, publisher names, trademarks, artwork, and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved.

