Why URL rewriting?
1, in favor of SEO, with parameters of the URL lower weight;
2, the address looks more formal, the promotion UID
Pseudo-static: Looks like a normal page, not a dynamically generated page.
Principle: Read Request.url The requested URL (view-3.aspx) in Global.asax Application_BeginRequest
Then rewrite it with HttpContext.Current.RewritePath (Rewriteurl) (that is, by another page to process the request) (view.aspx?tid=3 format)
Http://www.cnblogs.com/hd/archive/2005/06/20/177633.html
You can also use Microsoft's Urlrewrite, as long as you modify the configuration file can be URL rewrite
Case: URL rewrite, rewriting view-3.aspx and the like to view.aspx?id=3
1.view.aspx.cs design, Lbmsg is a server-side lab control
stringid = request["ID"]; if(id! =NULL) { intval =Convert.ToInt32 (ID); Switch(val) { Case 1: Lbmsg. Text="First place! It's you! "; Break; Case 2: Lbmsg. Text="the second is the best! "; Break; Case 3: Lbmsg. Text="Although you are the third, I believe you can succeed! "; Break; default: Lbmsg. Text="The Revolution is not yet successful! Comrades still need to work hard! "; Break; } }
2.global.asax Design
protected voidApplication_BeginRequest (Objectsender, EventArgs e) {Regex reg=NewRegex (@". +view-(\d+). aspx");//defines a regular expression that () can be used to group varMatch = Reg. Match (HttpContext.Current.Request.Url.AbsolutePath);//URL path matching the current user input if(Match. Success)//determine if the match is successful { stringid = match. groups[1]. Value;//get the first set of valuesHttpContext.Current.RewritePath ("view.aspx?id="+ ID);//redirect pages, transfer requests } }
3. When the user input view-3.aspx, automatically when the view.aspx?id=3 processing
URL rewrite urlrewrite