ASP. Net URL Rewrite

Source: Internet
Author: User
Tags rar

ASP. Net URL Rewrite

Today, I studied the problem of the day.
Want to implement such as: HTTP://WWW.ZIUZIU.CN/2008/2/2
Http://www.ziuziu.cn/default.html
And so the URL
Of course, the program directly generates static pages that can be implemented
But that's going to generate a lot of these pages and folders
And it's a waste of time to generate large amounts of data.
In this case it is necessary to implement the URL rewrite, of course, there are many ways
The following is a urlrewriter approach to Microsoft

1. First download the URLRewriter.dll, and then copy it directly to the bin directory of your website.
Http://ziuziu.cn/download/URLRewriter.rar
2. Configure your Web. config file
Under the <configuration> node, add
<configSections>
<section name= "Rewriterconfig" type= "URLRewriter.Config.RewriterConfigSerializerSectionHandler, Urlrewriter"/ >
</configSections>

<RewriterConfig>
<Rules>
<!--a three of the tests I wrote myself, of course, you can write a lot of them.
<!--This is the page that http://localhost:2001/default.aspx?id=1 generated http://localhost:2001/d1.aspx
<RewriterRule>
<LOOKFOR>~/D (\d{0,5}) \.aspx</lookfor>
<SendTo>~/default.aspx?ID=$1</SendTo>
</RewriterRule>
<!--This is the page that http://localhost:2001/article.aspx?id=1 generated http://localhost:2001/1/a.html
<RewriterRule>
<lookfor>~/(\d{0,5})/a\.html</lookfor>
<SendTo>~/article.aspx?id=$1</SendTo>
</RewriterRule>
<!--This is the page that http://localhost:2001/test.aspx?id=1 generated http://localhost:2001/1/
<RewriterRule>
<lookfor>~/(\d{0,5})/</lookfor>
<SendTo>~/test.aspx?id=$1</SendTo>
</RewriterRule>

</Rules>

</RewriterConfig>

Also in the <system.web> configuration section, add
<add verb= "*" path= "*.aspx" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>
<add verb= "*" path= "*.html" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>
<add verb= "*" path= "*" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>

3. Okay, basically, but it's important to remember.
There are three scenarios for URL generation
For the first case, the first and second steps are configured to achieve
For the second and third URL situations, you need to configure
Let's start with the second case: because we're rewriting the. html suffix
So the. HTML mapping needs to be done in IIS, as follows:
Right-click Site-Properties-Home Directory-Configuration
In the open page, look for the extension. aspx, double-click to copy the executable file in the pop-up window
It's usually C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.
Click Add in Popup window to copy content to executable file
Extension. HTML of course you can write any of this, but with
<add verb= "*" path= "*.html" type= "Urlrewriter.rewriterfactoryhandler, Urlrewriter"/>
Remain consistent.
Also remove the confirmation file exists, OK
Enter http://localhost:2001/1/a.html after completion
Is it okay to visit?

The third scenario is described below, which generates the table of contents
It's a little bit more complicated, and it's also configuring IIS
Or in that pop-up window, dot insert
The copied file is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.
Copy into the executable box, and remove the confirmation file exists, OK
So input http://localhost:2001/1/, is it possible to access the? Hey
Perhaps the reader will have a question: what is the difference between this and the second setting now?
Now the set is actually to do the * mapping, that is, all the files are URL rewrite handler processing
In this case, you can actually remove the. html and your own. aspx mappings, which can also be generated. Html/.aspx/url
Well, if you want to expand it, let's expand it.

4. Now let's talk about the issues that the mapping should pay attention to
Because * mapping is to give all the files to the URL thanks to the program to deal with, this will cause the site of the image and CSS
or some download of RAR and other files to be processed, so it will be slow? The answer is no doubt, it will definitely increase the memory,
A single site image and uploaded images are enough to slow the program down exponentially.
Is there any way to deal with it?
Of course, we can perform the following processing to restore the speed:
Method 1, the folder where the picture is stored into a virtual directory, and then move the virtual directory, * * mapping, so that his URL rewrite program will not process the picture file, of course, the storage of other files do not need the URL rewrite program to do similar to the image folder to do the same processing.
Virtual Directory Setup Method: Right-click Directory Point properties in the IIS site, directory-point creation
Then click Configure, Delete in the popup window: the map of *. * Added under the wildcard application mapping (execution order).
Method 2, the folder does not need to set the * * Mapping of the new site and the original site separate, so that the original site when access to use
The domain name of the new site can be. For example, the image set site http://images.ziuziu.cn, so that when the http://ziuziu.cn site to access the picture, you must use the http://images.ziuziu.cn/name. gif, which avoids all the processing of the Ask.
The above two methods can improve a lot of speed, of course, the first kind of medicine more convenient.

5. The final treatment of the situation of the postback can be searched online.


Article Source: http://www.diybl.com/course/4_webprogram/asp.net/asp_netshl/2008414/110348.html

ASP. Net URL Rewrite

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.