View code
The interception Request Code rewrite. First, it intercepts the URL request, analyzes the current URL, and finally jumps to the corresponding page. so our first step is to intercept URL requests. to create a new class library named URL, reference urlrewriter in this class library. DLL. create a class named myrewritter. CS, the Code is as follows namespace URL {public class myrewritter: urlrewriter. basemodulerewriter {protected override void rewrite (string requestedpath, httpapplication APP) {If (requestedpath. contains ("News/2011/3/2. html ") app. context. rewritepath ("/news. aspx? Id = 2 & year = 2011 & month = 3 "); elseapp. Context. rewritepath ("/here. aspx ") ;}} you can see that this class inherits urlrewriter. basemodulerewriter. As long as the current URL request is news/2011/3/2. html, We will rewrite the page to/news. aspx? Id = 2 & year = 2011 & month = 3. this is just a simple example. In fact, the URL judgment is generally completed using a regular expression. the correspondence between pages may need to be completed by querying the database. web. the Config code references this class library in the website project. then modify the web. config, the following: <? XML version = "1.0"?> <Configuration> <etettings/> <connectionstrings/> <system. web>