Configure the urlrewriter pseudo URL to implement pseudo-static!

Source: Internet
Author: User

In Asp.net, sometimes we do not actually put the website static, but adopt URL rewriting to implement pseudo static. The advantages of pseudo-static will be explained in the next section. Let's not talk about it much. Next we will configure the URL:

Step 1Download this component. Decompress the package and copy urlrewriter. DLL to your project bin directory.

Step 2, Add the following to Web. config:

<? XML version = "1.0" encoding = "gb2312"?>
<Configuration>
<Configsections>
<Section name = "rewriterconfig" ype = "urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter"/>
</Configsections>

Add the rewritten rule node:
<Rewriterconfig>
<Rules>
<Rewriterrule>
<Lookfor> ~ /Examples/(. [0-9] *) \. html </lookfor>
<Sendto> ~ /Search/search_sell.aspx? Id = $1 </sendto>
</Rewriterrule>
</Rules>
</Rewriterconfig>

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> ):

<Httphandlers>
<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 4In IIS \ your site \ properties \ main directory \ Configuration \ add an extension item with the same configuration as the ASPX page. The extension name is .html. Do not check "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:
<Httphandlers>
<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.

Method 1

For the ASPX page, we can view it on the clientCodeIt automatically adds an action to the form, and the address is the original page address at the beginning. For An ASPX page, if its action is empty, it will be sent back to the current address. In this way, you can clear the action on the client to ensure that the address remains available after sending the response.

Add the following code to the page:
<SCRIPT type = "text/JavaScript"> try {document. Forms [0]. Action = ""} catch (Ex) {}</SCRIPT>
If there is a form page, add the above Code to <form> </form>. If it is a user control, directly add it to the page.
This method is the simplest and most useful method and has been tested.

Method 2

Step 6, Added components 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:
<% @ Register tagprefix = "SKM" namespace = "actionlessform" assembly = "actionlessform" %>
Change <form...>:
<SKM: Form ID = "Your form name" method = "Post" runat = "server">
.....
</SKM: Form>

 

Multiple parameters:
Web. config
<Rewriterrule>
<Lookfor> ~ /Product/SUB/y/([A-Za-z0-9 \ s] +)/([A-Za-z0-9 \ s] +) \. html </lookfor>
<Sendto> ~ /Product/sub_category.aspx? Txt_l0 = $1 & amp; txt_l1 = $2 & amp; showbrand = Y </sendto>
</Rewriterrule>

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.