Asp tutorial. net iis urlrewrite implementation
The implementation in the asp.net tutorial is very simple. First, you need to reference two dll: actionlessform in your project. 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, see the bottom of the article. 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>
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 application configuration and click "add" button.
4. Enter the asp.net ing file in the executable file to copy the. aspx ing, for example, c: windowsmicrosoft. netframeworkv2.0.50727aspnet _ isapi. dll of. net 2.0.
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/