Hello everyone, again to meet with you, this time to bring you the URL rewrite, about the URL rewrite is what, what benefits, how to rewrite, today I share my experience with you
First, URL rewrite
URL rewriting is the process of first getting a URL request to enter and then rewriting it to another URL that the site can handle. For example, if the URL that comes in through the browser is "userprofile.aspx?id=1" then it can be rewritten as "userprofile/1.aspx".
Ii. Advantages of URL rewriting
1, in favor of Baidu, Google and other search engines included in the crawl, if you are the site optimization master, this is the basic skills ...
2, more readable, camouflage your technology to achieve, so that others want to attack you have a certain degree of difficulty!!!
Third, how to rewrite the URL
1, ASP. NET implementation a total of two
A. Using HttpModule to process URLs in request requests
B. Implementing URL rewriting with plug-in IIS Rewrite components
2. HttpModule implements URL rewriting
A. Handwritten look at HttpModule, clearly described HttpModule in the entire page request process in the low, HttpModule is the dynamic request is the only way.
C. Case studies to give you a deeper understanding of the mysteries
The first step: modify the following code
Scene: There are two pages, data list page and data detail page, click on the list page data into the detailed page, we want to do the data list page connection to make the following changes
Modified before: <asp:hyperlink id= "Hktitle" runat= "Server"
Navigateurl= ' <%# Eval ("Id", "bookdetail.aspx?id={0}")%> ' > Data title </asp:HyperLink>
Modified: <asp:hyperlink id= "Hktitle" runat= "Server"
Navigateurl= ' <%# Eval ("Id", "bookdetail_{0}.html")%> ' > Data title </asp:HyperLink>
The second step: Create HttpModule, the code is as follows
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;/// <summary>///Summary description of Demomodule/// </summary> Public classdemomodule:ihttpmodule{/// <summary> ///Start processing Request Events/// </summary> /// <param name= "Sender" ></param> /// <param name= "args" ></param> Private voidContext_beginrequest (ObjectSender,eventargs args) { //Get HttpApplicationHttpApplication application = Sender asHttpApplication; //gets the URL of the user request stringOldurl =application. Request.rawurl; //if the "Bookdetail" character is present in the request for processing requests if(Oldurl.indexof ("Bookdetail") >0) { //A string that intercepts the position before Bookdetail stringNewurl = oldurl.substring (0, Oldurl.indexof ("Bookdetail")); //The requested new string is "Bookdetail.aspx?bid=xxxxxxxx"Newurl = Newurl +"bookdetail.aspx?bid="+ oldurl.substring (Oldurl.lastindexof ("_") +1, (Oldurl.indexof (".")-Oldurl.lastindexof ("_") -1)); //To rewrite the URL in the requestapplication. Context.rewritepath (Newurl); } } Public voidDispose () {Throw Newnotimplementedexception (); } /// <summary> ///Initializing Events/// </summary> /// <param name= "context" ></param> Public voidInit (HttpApplication context) {//associating a request start eventContext. BeginRequest + =NewEventHandler (context_beginrequest); }}
Step Three: Configure HttpModule, which is configured as follows in Web. config
<system.web> "demomodule" type=" demomodule"/>
Fourth step: Experience the effect bar today, and there is a URL rewrite method, there is time to complete, we quickly experience it!!!
Original: http://blog.csdn.net/songyuhongnannan/article/details/7493499
ASP. HttpModule URL Rewrite (i) "Z"