Implementation of two-level domain name by Universal parsing and pseudo-static under ASP.net

Source: Internet
Author: User
Tags httpcontext iis interface net string split domain domain name
It was finally realized, but as a programmer, I always felt that I could not grasp the core of technology by using other components that were not open source. In fact, Microsoft has left an interface for us in net, let us do whatever we want.

First we can get a picture of the life cycle of. Net.

As you can see from the figure above, the server destroys the instance of a new HttpContext instance at the request of each different user until the request is complete. And Ihttpcontext is an HttpContext externally exposed interface, which contains 2 methods: Dispose () and init (HttpApplication context), We can achieve ihttpcontext and achieve HttpContext.
Key code:
Copy Code code as follows:
HttpApplication app = (HttpApplication) sender;
HttpContext context = App. context;
String url = context. Request.Url.AbsoluteUri; Full URL
string turl = URL. Split (".") [0];
String surl = Turl. ToLower (). Replace ("http://", "");
StringBuilder strb = new StringBuilder ();
Strb. Append (URL);
Strb. Append (sURL);

App. Context.rewritepath (Path, String. Empty, Strb. ToString (). Split ("?") [1]);
In Web.config configuration:
<system.web> Add the following code.
<add type= "Common.urlrewriter" name= "Common"/>
When you finally set up IIS, remember to set the table header for IIS to NULL.
Run it, and you'll be able to achieve it.

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.