You can use the ISAPI filter to rewrite the URL at the IIS web server level, or use the HTTP module or HTTP processing.ProgramImplements URL rewriting at the ASP. NET level.
In DOTNET, you only need to perform the following steps to implement urlrewriter:
Step 1: Add DLL reference urlrewriter. dll
Step 2: Configure in the web. config file
Add a section first
< Configuration >
.......
< Configsections >
< Section Name = "Rewriterconfig" Type = "Urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter" />
</ Configsections >
Then add a module httpmoudles,
Specify configuration information for the URL rewriting Engine
<System. Web>
.....
<Httpmodules>
<AddType= "Urlrewriter. modulerewriter, urlrewriter"Name= "Modulerewriter"/>
</Httpmodules>
Note the location of the Section
< System . Web > And < Configsections > The two sections are of the same level.
Add Rules again < Rewriterconfig >
< Rules >
<! -- Rules for Blog content Displayer -->
< Rewriterrule >
< Lookfor > /CTRL/(. *). ashx </ Lookfor >
< Sendto > /Controlcontainer. aspx? Control =/CTRL/$1. ascx </ Sendto >
</ Rewriterrule >
< Rewriterrule >
< Lookfor > CTRL/(. *). ashx </ Lookfor >
< Sendto > /Controlcontainer. aspx? Control = CTRL/$1. ascx </ Sendto >
</ Rewriterrule >
</ Rules >
</ Rewriterconfig >
This section is at the same level as <system. Web>.
Note that if the path in the sendto section is not set properly, Error 404 will be reported!
All requests from the path http: //.../CTRL/111. ashx are composed/Controlcontainer. aspx? Control =/CTRL/111. ascx to process
In addition to specifying whether to use the HTTP module or the HTTP processing program for rewriting. the Config File also contains a rewrite rule: the rewrite rule consists of two strings: The pattern to be searched in the requested URL; the pattern string to be replaced (if found ). In the Web. config file, this information is expressed in the following syntax:
<Rewriterconfig> <rules> <rewriterrule> <lookfor> the mode to be searched </lookfor> <sendto> string to replace the mode </sendto> </rewriterrule> <rewriterrule> <lookfor> the mode to be searched </lookfor> <sendto> string to replace the mode </sendto> </rewriterrule>... </rules> </rewriterconfig>
Each rewrite rule is composed of <Rewriterrule> Element expression. The pattern to be searched by <Lookfor> The element is specified, and the string to replace the pattern found will be in <Sentto> Input in the element. These rewrite rules are calculated from start to end. If the URL matches a rule, the URL is overwritten and the search for the rewrite rule is terminated.
when specifying a pattern in the lookfor element, note that regular expressions must be used for matching and string replacement. (Later, we will introduce a real example to illustrate how to use regular expressions to search for patterns .) Since the mode is a regular expression, ensure that any reserved characters in the escape regular expression are retained. (Some regular expressions retain the following characters :.,?, ^, $, And others. You can escape these characters by adding a backslash (for example, \.) to match the text periods .)