URL rewrite urlrewrite

Source: Internet
Author: User

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

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.