Implementing URL rewriting using Urlrewriter

Source: Internet
Author: User

Advantages

1) Hide real URLs for increased security

2) More friendly URLs, good to remember (see the Blog Park on the line to know)

3) easy to search engine included

.........

Possible drawbacks

Using URL rewriting can result in:

1) problem with picture path

2) problems with CSS paths

3) Performance issues

.........

First download the DLL package, with the source code.

Download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/msdnurlrewriting.msi

URLRewriter.dll and ActionlessForm.dll

Or just use the DLL I have uploaded: Http://files.cnblogs.com/yun_shuai/URLRewriter.rar contains the above 2 DLLs

How to: Add a reference in a Web project

Configuration in Webconfig:

1 <configSections> Increase in node:

<section name= "Rewriterconfig" type= " Urlrewriter.config.rewriterconfigserializersectionhandler,urlrewriter "/>

2 <configuration> Add URL rewrite configuration to the root node: You can use regular expressions

     <RewriterConfig> <Rules>   <!--Rules for Blog Content displayer--  &LT ; Rewriterrule>    <lookfor>~/(\d{4})/(\d{2})/(\d{2}) \.aspx</lookfor>    < sendto>~/showblogcontent.aspx?year=$1&amp;month=$2&amp;day=$3</sendto>   </RewriterRule >   <RewriterRule>    <lookfor>~/(\d{4})/(\d{2})/default\.aspx</lookfor>     <sendto><! [cdata[~/showblogcontent.aspx?year=$1&month=$2]]></sendto>   </RewriterRule>   < Rewriterrule>    <lookfor>~/(\d{4})/default\.aspx</lookfor>    <sendto>~/ showblogcontent.aspx?year=$1</sendto>   </RewriterRule>     <!--Rules for Product Lister -  <RewriterRule>    <LookFor>~/Products/Default\.aspx</LookFor>     <SendTo>~/ListCategories.aspx</SendTo>  </RewriterRule>   <RewriterRule>    <LookFor>~/Products/Beverages\.aspx< /lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=1</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/condiments\.aspx</lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=2</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/confections\.aspx</lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=3</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/dairy\.aspx</lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=4</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/grainscereals\.aspx</lookfor>    <Sendto>~/listproductsbycategory.aspx? categoryid=5</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/meatpoultry\.aspx</lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=6</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/produce\.aspx</lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=7</sendto>   </RewriterRule>   <RewriterRule>    <lookfor>~/ Products/seafood\.aspx</lookfor>    <sendto>~/listproductsbycategory.aspx? categoryid=8</sendto>   </RewriterRule> </Rules>   </RewriterConfig>

3

Or

4 complete.

5 Other questions:

True path reproduction after postback:

1. Add ActionlessForm.dll to the Bin folder of the project

2. Add <%@ Register tagprefix= "RW" namespace= "Actionlessform" assembly= "Actionlessform" in the code of the ASPX page%>

3. Then change the Form label to Rw:form (notice that both start and end are changed), TagPrefix can be customized

Additionally: DOTNET3.5 provides the System.Web.Routing namespace

You can implement the desired URL rewrite yourself.

Reference article:

Http://www.cnblogs.com/Ferry/archive/2009/06/19/1506770.html

Http://www.blogjava.net/Unmi/archive/2010/06/14/323349.html

As you can see from the 2 article addresses above, the server also uses URL rewriting methods

Implementing URL rewriting using Urlrewriter

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.