ASP. NET 301 permanent redirect for entire station using Web. config

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.