Global.asax's Application_BeginRequest implements URL rewrite with no suffix code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.