without change, the page path is index.aspx?id=1, and now when you enter the page path INDEX/1, you can also access the page, a process called URL rewriting①: Create a path rewrite rule in a class, the following is a custom Urlrewriterfilter class, you need to inherit the interface IHttpModule②: Configuration in the configuration file (if the custom class is written in another class library, you need to change the. dll file generation path for that class library to match the startup item. dll file path) In addition, the URL rewrite of ASP can be configured directly when the website is published, and IIS chooses URL rewriting function .The first step:
usingSystem;usingSystem. Collections. Generic;usingSystem. Linq;usingSystem. Text;usingSystem. Threading. Tasks;namespacehttpmodule{usingSystem. Web; usingSystem. Text. RegularExpressions; Public classUrlrewriterfilter:ihttpmodule { Public voidDispose () {Throw Newnotimplementedexception (); } /// <summary> ///responsible for registering a rewrite INDEX/1 on the first pipeline event URL for index.aspx?id=1/// </summary> /// <param name= "context" ></param> Public voidInit (HttpApplication context) {context. BeginRequest+=context_beginrequest; } voidContext_beginrequest (Objectsender, EventArgs e) { //01. Get the original URL of the current request INDEX/1 stringURL =HttpContext. Current. Request. RAWURL; //02. Rewrite the current URL//define a regular expression to check if the currently sent URL is the index page path I want to overrideRegex reg =NewRegex ("/index/(. *)" ); if(reg. IsMatch (URL)) {stringNewurl = Reg. Replace (URL,"/index.aspx?id=$1" ); HttpContext. Current. RewritePath (Newurl); } } }}
Step Two:
< system.webserver > < modules > < add name ="" type =" /c9>"/> </modules > </system.webserver >
ASP. NET page URL rewrite