URL rewriting is to disguise a dynamic page as a "static page". On the one hand, it can hide the real page file address, and on the other hand, it is also good for the search engine. (This is the best method in the space that does not support urlwrite. NET components)
In ASP. NET, using global. asax can easily achieve this goal. The principle is simple and the specificCodeYou can see at a glance:
Code
Protected Void Application_beginrequest (Object sender, eventargs E)
{
// Article_detail.aspx? Id = 1 to article_1.aspx
String Oldstring = @" (. *)/Article _ (\ D +) \. aspx " ;
String Newstring = @" Article_detail.aspx? Id = $2 " ;
System. Text. regularexpressions. RegEx oreg = New System. Text. regularexpressions. RegEx (oldstring );
If (Oreg. ismatch (request. url. tostring ()))
{
String Rewriteurl = Oreg. Replace (request. url. tostring (), newstring );
Httpcontext. Current. rewritepath (rewriteurl );
}
Oreg = Null ;
}