Asp. NET using Urlrewriter to realize pseudo-static experience sharing

Source: Internet
Author: User
Tags config expression regular expression
Urlrewriter is a URL rewrite component that Microsoft has packaged. Using it allows me to save a lot of my own development time.

Well, start telling my application experience, this is just a rookie experience, the master will not have to see.

The first step is to download this component from here. Unzip the UrlRewriter.dll copy to your project Bin directory.

In the second step, add in the web.config:

<?xml version= "1.0" encoding= "gb2312"?>
<configuration>
<configSections>
<section name= "Rewriterconfig" type= "URLRewriter.Config.RewriterConfigSerializerSectionHandler, Urlrewriter"/ >
</configSections>

The second step is to add the overridden rule node:

Such as:

<rewriterconfig>
<rules>
<rewriterrule>
<lookfor>~/sell/(. [ 0-9]*). Html</lookfor>
<sendto>~/search/search_sell.aspx?id={getproperty (Content)}</SendTo
</rewriterrule>
<rewriterrule>
<lookfor>~/sell/search_sell.aspx<       ;/lookfor>
<sendto>~/search/search_sell.aspx</sendto>
</rewriterrule>
<rewriterrule>
<lookfor>~/buy/(. [ 0-9]*). Html</lookfor>
<sendto>~/search/search_buy.aspx?id={getproperty (Content)}</SendTo>
</rewriterrule>
<rewriterrule>
<lookfor>~/buys/(. [       0-9]*). Html</lookfor>
<sendto>~/buys/show.aspx?id={getproperty (Content)}</sendto>
</rewriterrule>
</rules>
</rewriterconfig>

This will be based on your needs, if you are not familiar with the regular expression, then there is no way, or by virtue of your high IQ to find the law, a slight change can be used for you. Oh. If it's not clear, then Google the regular expression of the bar. (I began to refer to other people's configuration guess, even with the right, hehe.) Later, I looked at the relevant data and found this stuff very useful. )

The third step is to add the module configuration (written in <system.web>):

Such as:

<add verb= "*" path= "*.aspx" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>

(this means using an HTTP program to handle overrides)

Well, now we can try it out.

So input: Http://127.0.0.1:8080/Sell/1.aspx appeared, hehe. But if it were changed to: http://127.0.0.1:8080/Sell/1.html

Dizzy, found no. Sweat...

Oh, the reason is not to parse the HTML with asp.net ISAPI.

The solution is ...

The fourth step, in IIS your site properties home directory configuration the same extension entry for the same configuration as the ASPX page. Note "Verify that the file exists" do not tick, otherwise a file cannot be found.

Now let's try it again. What the? #¥%#¥%#, or not. Oh. Don't worry, let's go back and look at it, we didn't configure it in Web.config. HTML also uses modules for this parsing.

Step fifth, add in the module configuration:

<add verb= "*" path= "*.aspx" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>
<add verb= "*" path= "*.html" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>

Now can always, huh, huh. Finally see, excited bar. Don't worry, it's just the simplest. If your page has a postback. For example, put the DataGrid, there are pagination, you point to the next page to find, fainted, and problems.

What to do, this is actually a micro-software site on the said, I am here briefly.

Step sixth, add the form to keep the component:

Find ActionlessForm.dll in the original item you downloaded and put it in your project Bin directory.

And then add it to your page:

<%@ Register tagprefix= "SKM" namespace= "Actionlessform" assembly= "Actionlessform"%>
Then change your <Form...> to:
<skm:form id= "Your table Single-name" method= "POST" runat= "Server" >
.....
</skm:Form>

That's all. Now you can relax. Everything is as you wish.

Finally, I wish you all the best.



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.