ASP. net url rewriting for new bottled old wine

Source: Internet
Author: User

Recently, my friend's search engine is quickly developed. Some front-end work still needs to be completed. For example, the search interface, display interface, data paging, and search recommendations. Because the entire product is developed based on C #, You can query the string WD on the search page (search. aspx. Refer to the baidu search page, such as search blog garden, will display http://www.baidu.com/s in the address bar? WD = blog Park: locate the search keyword through WD. If we want to make our search. aspx into S? WD = What are the benefits of the blog garden? There are many, and 100 words are omitted here. What technology is used? I use urlrewriter.

To use urlrewriter, you must first add urlrewriter to the reference. Then add the response configuration section in Web. config. Want to make when entering http://www.applls.com/s in the address bar? WD = blog, which automatically processes requests in search. aspx. I configured it according to the following operations. My testing environment is win7 + iis7.0 + vs2008.

1: add the <section name = "rewriterconfig" requirepermission = "false" type = "urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter"/> node to the configsections ctions node. The name can be changed at will.

2: configure the URL ing Based on the URL you want to match. I want to match in the address barS? WD= Blog, add the rewriterconfig node with the same name as the Section node in step 1 in configuration. The structure is as follows:

 

<Rewriterconfig>
<Rules>
<Rewriterrule>
<Lookfor> ~ /S? WD = ([A-Z, A-Z, 0-9] +) </lookfor>
<Sendto> ~ /Demo. aspx? WD = $1 </sendto>
</Rewriterrule>
<Rewriterrule>
<Lookfor> ~ /S </lookfor>
<Sendto> ~ /Demo. aspx </sendto>
</Rewriterrule>
</Rules>
</Rewriterconfig>

3: configure the following nodes on the httphandlers node, which means that the requests to s are processed by urlrewriter. rewriterfactoryhandler and urlrewriter.

<Add verb = "*" Path = "S" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>

4: Add the following configuration on the modules node,

<Add name = "modulerewriter" type = "urlrewriter. modulerewriter, urlrewriter"/>

5: configure the following nodes under the handlers node.

<Add name = "urlrequestc" verb = "*" Path = "S" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>

After the above configuration, when the address bar requestS? WD= In the blog Garden, the background will be automatically processed on the search. ASPX page.

Extension,

1: If the request in the address bar ([A-Z, A-Z, 0-9] +). aspx file is mapped to the demo. ASPX page for processing. Add new configuration

<Rewriterrule>
<Lookfor> ~ /([A-Z, A-Z, 0-9] +). aspx </lookfor>
<Sendto> ~ /Demo. aspx? WD = $1 </sendto>
</Rewriterrule>
Add <add verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/> to httphandlers.

Add <Add name = "URLRequest" verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/> to handlers.

To solve the problem.

2: If the request ([a-z,a-z,0-9]+).html in the address bar is mapped to the demo. ASPX page for processing, this is called pseudo-static processing.

<Rewriterrule>
<Lookfor> ~ /([A-z,a-z,0-9]+).html </lookfor>
<Sendto> ~ /Demo. aspx? WD = $1 </sendto>
</Rewriterrule>

Add <add verb = "*" Path = "*. html" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/> to httphandlers.

Add <Add name = "URLRequest" verb = "*" Path = "*. html" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/> to handlers.

The above problems can be solved.

3: If the request specifies a suffix file such as ([A-Z, A-Z, 0-9] +). yoolo, all are mapped to the demo. ASPX page for processing. With this, we can define the suffix as our favorite suffix after developing the ASPX page.

<Rewriterrule>
<Lookfor> ~ /([A-Z, A-Z, 0-9] +). yoolo </lookfor>
<Sendto> ~ /Demo. aspx? WD = $1 </sendto>
</Rewriterrule>

Add <add verb = "*" Path = "*. yoolo" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/> to httphandlers.

Add <Add name = "URLRequest" verb = "*" Path = "*. yoolo" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/> to handlers.

In addition,

Symptom A: differences between httphandlers and handlers in the web. config configuration section. After reading the help document of msdn, I mentioned that httphandlers is based on the configuration before iis6.0, while handlers is based on the configuration of iis7.0. Therefore, when matching each ing, both httphandlers and handlers must be configured once.

Symptom B: When configuring the ing, if only the handlers node is configured, httphandlers is not configured. You can rewrite the URL in iis7.0. You cannot rewrite the URL when you start vs2008 to browse the page. Therefore, I estimate that the port started in vs2008 is simulating the Web service environment of iis6.0, which is different from iis7.0.

Based on the above two phenomena, I do not know whether I understand them correctly. There are other applications for URL rewriting. You can also follow the instructions below.

The entire DLL Code of urlrewriter is very short, so it is decompiled and produced CS files. If you need to debug the tracing, you can attach it to your project and download it here.

I hope you can give me some advice on how to install the wine. Welcome to shoot bricks.

Related Article

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.