Implementation of second-level domain names through wildcard DNS and pseudo-static in asp.net

Source: Internet
Author: User

Although it was finally implemented, as a programmer, I always felt that I could not grasp the core of the technology by using other components that are not open source. In fact, in net, Microsoft has left an interface for us to do whatever we want.

First, we can take a picture to understand the. net lifecycle.

As you can see, the server creates a new HttpContext instance for each request of different users until the request ends and the server destroys the instance. Ihttpcontext is an interface made public by httpcontext. It contains two methods: dispose () and Init (HttpApplication context). We can implement Ihttpcontext to achieve httpcontext.
Key code:
Copy codeThe Code is as follows:
HttpApplication app = (HttpApplication) sender;
HttpContext context = app. Context;
String url = context. Request. Url. AbsoluteUri; // complete 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, configure the following:
Add the following code in <system. web>.
<HttpModules>
<Add type = "Common. URLRewriter" name = "Common"/>
When setting IIS, remember to set the IIS header to null.
You can achieve this by running
</HttpModules>

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.