ASP. net url rewriting

Source: Internet
Author: User

 

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> 

 

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.