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.