Asp.net implements 301 redirection using code

Source: Internet
Author: User
The company's website (http://www.maxray.cn) server is not hosted, just put in the company, but before the company's fixed IP port 80 was closed, tried many times is port 80 and port 8080 is not available, in desperation, I had to use port 8022. However, this is not a solution for a long time. I still need to directly communicate with China Telecom to apply for port 80. After the unremitting efforts of my colleagues, finally, port 80 is activated, so that the company's website can be accessed through two ports at the same time. However, if this happens, search engines will think it is cheating, directly shut down the port 8022, And the click from the search engine will suddenly become invalid. In order to be friendly to the search engine, the best way is to perform 301 redirection. However, when I was doing a test with my colleagues yesterday, I found that the configuration was not successfully set directly on IIS, And it was detected that it was a loop page, you can only perform 301 redirection using code in the second solution. The related code is also very simple, and it is directly pasted below. If you need it, you can directly copy it for use. But please remind me, you need to change the website address of Jiangsu mingrui Information Technology Co., Ltd. to your website address. Do not jump to our website. Otherwise, the traffic will be lost. Protected void page_load (Object sender, eventargs E)  {  If (request. url. Port = 8022)  {   Response. Status = "301 moved permanently ";  Response. addheader ("location", "http://www.maxray.cn ");  }  }PS: When I wrote this blog, the QQ news popped up, saying that Gao Xiaosong was released soon. Six months later, the celebrities were celebrities, and two police cars were moved from jail, I saw the detailed news myself. Gao Xiaosong got out of jail this morning, his money soared, returned home for a short break, and immediately went to the United States.
Related Article

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.