1. Add configuration in Web. config
<appSettings> <add key= "Webdomain" value= "mhzg.net"/> <add key= "url301location" value= " Www.mhzg.net "/> </appSettings>
2. Create a new Class library project under the current solution
3, a new CS, named: Domain301.cs
Using system;using system.web;using system.configuration;namespace domain{public class Redirectnewdomain:ihttpmodule {public void Dispose () {} public void Init (HttpApplication context) { Context. AuthorizeRequest + = (new EventHandler (Process301)); } public void Process301 (object sender, EventArgs e) {HttpApplication app = (HttpApplication) sen Der HttpRequest request = App. Context.request; String lrequestedpath = Request. Url.DnsSafeHost.ToString (); String strdomainurl = configurationmanager.appsettings["Webdomain"]. ToString (); String strweburl = configurationmanager.appsettings["Url301location"]. ToString (); if (Lrequestedpath.indexof (strweburl) = =-1) {app. Response.statuscode = 301; App. Response.AddHeader ("Location", Lrequestedpath.replace (Lrequestedpath, "http://" + Strweburl + request.) Rawurl.tostring (). Trim ())); App. Response.End (); } } }}
4. Registering in Web. config
ASP. NET 301 permanent redirect for entire station using Web. config