Use urlrewriter for URL rewriting to implement a complete pseudo-static solution

Source: Internet
Author: User

The so-called pseudo-static page refers to URL rewriting, in ASP. net implementation is very simple first you need to reference two dll: actionlessform. DLL, urlrewriter. DLL, which is actually rewritten by urlrewriter. DLL, but if you want to implement paging, you must use this actionlessform. DLL. For file downloads, seeArticleBottom. Now let's take a look at the procedure:

Step 1: Download the component and copy urlrewriter. DLL to the bin directory of your project.

Step 2: Add the following content to <configuration> in Web. config:

<Configsections>
<Section name = "rewriterconfig" type = "urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter"/>
</Configsections>

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

<! -- The following is the URL rewrite rule -->

<Rewriterconfig>
<Rules>
<Rewriterrule>
<Lookfor> ~ /Products/jurisdiction _ (\ W {3}) \. aspx </lookfor>
<Sendto> ~ /En/jurisdiction. aspx? Jurid = $1 </sendto>
</Rewriterrule>

<Rewriterrule>
<Lookfor> ~ /Articles/(\ D {1,}) \. aspx </lookfor> <! -- This is the replaced file name, which uses a regular expression -->
<Sendto> <! [CDATA [~ /Article_view.aspx? Article_id = $1]> </sendto> <! -- This is a webpage to be replaced, generally a webpage with parameters following a question mark -->
</Rewriterrule>
<Rewriterrule>
<Lookfor> ~ /Articles/(\ D {1,}) _ (\ D {1,}) \. aspx </lookfor>
<Sendto> <! [CDATA [~ /Article_view.aspx? Article_id = $1 & page = $2]> </sendto>
</Rewriterrule>
<Rewriterrule>
<Lookfor> ~ /Examples/(. [0-9] * example .html </lookfor>
<Sendto> ~ /Search/search_sell.aspx? Id = {getproperty (content)} </sendto>
</Rewriterrule>
</Rules>
</Rewriterconfig>

Such as the above Web site http://www.bingd.com/Article_View.aspx? Article_id = 9 can be replaced with a http://www.bingd.com/Articles/9.aspx, of course, you can replace the extension after using any IIS can interpret the extension, if you like using HTM extension, if you configure the forwarding rule with the extension htm (Step 4 for HTML extension), some articles may be long and we usually divide an article into several pages, so based on the configuration above, if we want to access the http://www.bingd.com/Article_View.aspx? Article_id = 9 & page = 3 we can use http://www.bingd.com/Articles/9_3.aspx instead, so that when the search engine to grab your web page, will include your Web site, when someone finds your webpage, they can access the link from these addresses.

Step 3: add the module configuration (written in <system. Web> ):

<Httphandlers>
<Add verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
<Add verb = "*" Path = "*. html" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
</Httphandlers>

If iis7.0 is used, you don't have to worry about it. This step can be simplified to adding urlrewriter directly in the section in Web. config:

<Add name = "urlrewriter" type = "intelligencia. urlrewriter. rewriterhttpmodule, intelligencia. urlrewriter"/>

This ensures that all requests pass through the module of Asp.net.

Step 4: Use the ISAPI of Asp.net to parse HTML (HTM or other suffixes have the same operation method ):

1. Open IIS management and right-click site properties.
2. Switch to "main directory" and click "Configure" button.
3. Open the applicationProgramConfiguration, click "add" button.
4. Enter ASP in the executable file.. Net ing file, which can be copied. aspx ing: for example. NET 2.0: C: \ WINDOWS \ Microsoft. net \ framework \ v2.0.50727 \ aspnet_isapi.dll
Enter ". html" in the extension, and set the operation limit to "get, Head, post, debug" and "cancel" to check whether the file exists.

If your page has a return request. For example, if you put the DataGrid on the page and there are pages, you will find that the page goes down to the next page, and then you will find a problem again. What should I do now? In fact, I have mentioned it on Microsoft's website. I will briefly describe it here.

Step 5: add the component for form return Persistence:

Download actionlessform. dll and put it in your project bin directory. Then add the following to your page:

<% @ Register tagprefix = "SKM" namespace = "actionlessform" assembly = "actionlessform" %>

Change <form...>:

<SKM: Form ID = "Your form name" method = "Post" runat = "server"> ...... </SKM: Form>

Urlrewriter. dll: http://urlrewriter.net/

Urlrewriter. dll for the ms (contains actionlessform. dll): http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi

Source Freezing Point Network Garden: http://www.bingd.com/, Source Address: http://www.bingd.com/blog/html/UrlRewriter.htm

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.