Use URLRewriter to override the url address

Source: Internet
Author: User
First of all, download URLRewriter, download and install ghost, and find the URLRewriter. dll file in the bin directory.

Then, reference the file to the project and configure the file as follows:

1. Add the following code to the web. config file:

<Configuration>
<ConfigSections>
<Section name = "RewriterConfig" type = "URLRewriter. Config. RewriterConfigSerializerSectionHandler, URLRewriter"/>
</ConfigSections>

</Configuration>

Where

<Section name = "RewriterConfig"
Type = "URLRewriter. Config. RewriterConfigSerializerSectionHandler, URLRewriter"/>
</ConfigSections>

The handler class used to specify the configuration section "RewriterConfig" is named "URLRewriter. Config. RewriterConfigSerializerSectionHandler", which exists in the URLRewriter. dll file in the bin directory.

2. Add the following code to the system. web node in the web. config file:

<HttpHandlers>
<Add verb = "*" path = "*. html"
Type = "URLRewriter. RewriterFactoryHandler, URLRewriter"/>
</HttpHandlers>

This Code indicates that the file extension is.html All HTTP requests of the file are mapped to the class.URLRewriter. for details about RewriterFactoryHandler, refer to MSDN. Here I made a mistake. path = "*. html "is written as path =" *. aspx "causes a page not found and a 404 error occurs.

3. Rewrite the url

Like 1 <Configuration> </Configuration> below the node

The key is

 

<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor> ~ /Shownews/news (\ d +) \. html </LookFor>
<SendTo> ~ /Shownews. aspx? ShowID = $1 </SendTo>
</RewriterRule>
<RewriterRule>
<LookFor> ~ /Product (\ d +) \. html </LookFor>
<SendTo> ~ /Showproduct. aspx? ShowID = $1 </SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>

The key lies in the transformation of uml.

<LookFor> ~ /Shownews/news (\ d +) \. html </LookFor>

<SendTo> ~ /Shownews. aspx? ShowID = $1 </SendTo>

It means converting the first path into another path. The Regular Expression in <LookFor> () is the parameter $1 in the second sentence.

You can also use $2 $3 to represent the parameters in the second third () of <LookFor>.

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:
<% @ Register TagPrefix = "skm" Namespace = "ActionlessForm" Assembly = "ActionlessForm" %>
Change <Form...>:
<Skm: Form id = "Your Form name" method = "post" runat = "server">
.....
</Skm: Form>
That's All. Now you can rest assured

 

 

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.