Use httpmodules to change the website Domain Name

Source: Internet
Author: User

My friend's website, whose original domain name is sitea.com, is now changed to siteb.com. Of course, sitea.com has not expired yet. It may take a while. I read this article online.

How does an SEO website achieve 301 redirection? Http://smt.fortuneage.com/uemarketer/18655-155226.aspx

It means how to implement it in Asp.net. Previously, extensive domain names were implemented using urlrewriter. I checked some Nhibernate stuff a few days ago. Some friends also used httpmodules to create a session connection for each request and release the session after the request ends.

Yes, Microsoft provides something similar to the pipe chain, and one by one modules handles it. Of course, this method can also be used to determine that only authenticated users can download files with the corresponding extension, that is, they can be intercepted and processed before being handed over to the final result.

Of course, you can create a new class on your own and inherit from the public class goxuehttpmodule: ihttpmodule

 

Public class goxuehttpmodule: ihttpmodule
{

/// <Summary>
/// Constructor
/// </Summary>
Public goxuehttpmodule ()
{

}

# Region ihttpmodule Member
/// <Summary>
/// Release
/// </Summary>
Public void dispose ()
{

}

/// <Summary>
/// Initialization
/// </Summary>
/// <Param name = "context"> HTTP application </param>
Public void Init (httpapplication context)
{
Context. beginrequest + = new eventhandler (context_beginrequest );
// When the page is closed
// Context. endrequest + = new eventhandler (context_endrequest );
}
# Endregion

/// <Summary>
/// Start the request
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void context_beginrequest (Object sender, eventargs E)
{
String url = httpcontext. Current. Request. url. tostring ();
If (URL. Contains ("sitea.com "))
{
String url2 = URL. Replace ("sitea.com", "siteb.com ");
Httpcontext. Current. response. Status = "301 moved permanently ";
Httpcontext. Current. response. addheader ("location", url2 );
Httpcontext. Current. response. End ();
}
Else
{
Httpcontext. Current. response. Redirect (URL );
}

}

/// <Summary>
/// End the request
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void context_endrequest (Object sender, eventargs E)
{
}

}

 

Of course, the red above can be directly written in urlrewriter. modulerewriter, which not only implements the second-level domain name, but also implements the domain name change.

At the same time, the old access method can remain unchanged. The old search engine address will also be displayed with the new domain name URL.

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.