This article for everyone in detail under the use of Global.asax Application_BeginRequest implementation URL rewrite its no suffix, the specific core code as follows, there is a need for friends to refer to, I hope to help you
Use Global.asax's application_beginrequest to implement URL rewrite suffix
The code is as follows:
<%@ Application language="C #"%><script runat="Server">voidApplication_BeginRequest (Objectsender, EventArgs e) {stringOldurl = SYSTEM.WEB.HTTPCONTEXT.CURRENT.REQUEST.RAWURL;//Get initial URL//~/123.aspx→~/index.aspx?id=123Regex reg =NewRegex (@"^\/\d+\.html");if(Reg. IsMatch (Oldurl)) {stringid = Reg. Match (Oldurl). ToString (). Substring (1Reg. Match (Oldurl). ToString (). LastIndexOf (".") -1); Context.rewritepath ("~/index.aspx?id="+ID);}//~/123→~/index.aspx?id=123Regex REG1 =NewRegex (@"^\/\d+$");if(REG1. IsMatch (Oldurl)) {stringid = reg1. Match (Oldurl). ToString (). Substring (1); Context.rewritepath ("~/index.aspx?id="+ID);}//~/index/123→~/index.aspx?id=123Regex reg3 =NewRegex (@"^\/index\/\d+$");if(reg3. IsMatch (Oldurl)) {stringid = reg3. Match (Oldurl). ToString (). Substring (7); Context.rewritepath ("~/index.aspx?id="+ID);}}</script>
Global.asax's Application_BeginRequest implements URL rewrite with no suffix code