Asp.net urlrewriter experience

Source: Internet
Author: User

Step 1: Download the sample source code. Decompress the package and copy urlrewriter. DLL to your project bin directory.
Step 2: Add the following content to Web. config: CopyCode The Code is as follows: <? XML version = "1.0" encoding = "gb2312"?>
<Configuration>
<Configsections>
<Section name = "rewriterconfig" type = "urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter"/>
</Configsections>

Step 2: add the rewritten rule node:
for example, copy Code the code is as follows:


~ /Clusters/(. [0-9] *) \. html
~ /Search/search_sell.aspx? Id = $1

~ /Logs/search_logs \. aspx
~ /Search/search_sell.aspx

~ /Buy/(. [0-9] *) \. html
~ /Search/search_buy.aspx? Id = $1

~ /Buys/(. [0-9] *) \. html
~ /Buys/show. aspx? Id = $1


This depends on your needs. If you are not familiar with regular expressions, there is no way to find the regular expression or use your high IQ to find the regular expression. You can use it with a slight change. Haha. If you cannot figure it out, Google the regular expression. (I started to guess by referring to other people's configurations. I used it right, huh, huh. Later I read the relevant information and found it useful .)
Step 3: add the module configuration (written in <system. Web> ):
For example:Copy codeThe Code is as follows: <Add verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
</Httphandlers>

(HTTPProgramTo process the rewrite)
Now we can try it.
So the input: http: // 127.0.0.1: 8080/Hangzhou/1. aspx appears. However, if it is changed to: http: // 127.0.0.1: 8080/Hangzhou/1.html
Dizzy. Khan...
The reason is that we didn't use Asp.net's ISAPI to parse HTML parsing.
The solution is...
Step 4: add an extension item with the same configuration as the ASPX page in IIS \ your site \ properties \ main directory \ Configuration \. Note: Do not select "check whether the file exists". Otherwise, the file cannot be found.

Try again now. What? #¥ % # ¥ %. Haha. Don't worry. Let's take a look at it. We didn't configure. html in Web. config and used this module for parsing.

Step 5: add the following to the module configuration:Copy codeThe Code is as follows: <Add verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
<Add verb = "*" Path = "*. html" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
</Httphandlers>

It's okay now, huh, huh. I am so excited. Don't worry, it's just the simplest. 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 6: add the component for form return Persistence:
Find actionlessform. dll in the project you downloaded and put it in the bin directory of your project.

Then add the following to your page:Copy codeThe Code is as follows: <% @ register tagprefix = "SKM" namespace = "actionlessform" assembly = "actionlessform" %>
Change <form...>:
<SKM: Form ID = "Your form name" method = "Post" runat = "server">
.....
</SKM: Form>

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.