In net Microsoft has left us an interface that lets us do whatever we want.
First, we can get a picture of the life cycle of the. Net.
As you can see, for each different user's request, the server creates a new HttpContext instance until the request is finished and the server destroys the instance. Ihttpcontext is an externally exposed interface of HttpContext, which contains 2 methods: Dispose () and init (HttpApplication context), We can achieve ihttpcontext so as 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; 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]);
Under configuration in Web. config:
Add the following code in the <system.web>.
<add type= "Common.urlrewriter" name= "Common"/>
When you finally set up IIS, remember to set the IIS header to empty.
You can make it work.
Implementation method of two-level domain name implementation by Universal parsing and pseudo-static under ASP.