I have rewritten my website.Program, In the use of msdn
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnaspp/html/urlrewriting. asp
URL rewrite Method
Today, I found that the record of the original access address is still in the search engine, and many of my friends access the address through it.
Of course, I don't want to consider that all these connections are directed to the error page, so I want to add a rule in the URL rewirte.
<Lookfor> ~ /Showarticle. aspx \? Id = (\ D +)
<Sendto> is ~ /Show. aspx \? Id = (\ D +)
When I access this page, Error 404 is reported.
Take a closer look at the url writeCode
Last found
Protected virtual void rewritermodule_authorizerequest (Object sender, eventargs E)
{
Httpapplication APP = (httpapplication) sender;
Rewrite (App. Request. Path, APP); // here, request. Path is used.
}
Tested by me
For an address http: // localhost/test/requestpath. aspx/SSS. aspx? Id = 2222 access
The result is:
Request. Path:/test/requestpath. aspx/SSS. aspx
Request. url. tostring (): http: // localhost/test/requestpath. aspx/SSS. aspx? Id = 2222
Request. pathinfo:/SSS. aspx
Request. rawurl:/test/requestpath. aspx/SSS. aspx? Id = 2222
I changed the above Code
Protected virtual void rewritermodule_authorizerequest (Object sender, eventargs E)
{
Httpapplication APP = (httpapplication) sender;
Rewrite (App. Request. rawurl, APP );
}
When I run my program, I find that my program reports an error, prompting that my parameters are incorrect,
After tracking, we found that querystring passed two ID parameters.
After tracking code, we found that internal static void rewriteurl (httpcontext context, string sendtourl, out string sendtourllessqstring, out string filepath)
If (context. Request. querystring. Count> 0)
{
If (sendtourl. indexof ('? ')! =-1)
{
Sendtourl + = "&" + context. Request. querystring. tostring ();
}
Else
{
Sendtourl + = "? "+ Context. Request. querystring. tostring ();
}
}
Here, context. Request. querystring is added to sendtourl.
If this part is removed, all pages without the querystring parameter cannot be passed correctly.
At last, only when rewrite. config is available
<! --
If lookfor contains querystring, you do not need to write querystring in sendto,
Because the context. Request. querystring of the context content has been passed
-->
<Rewriterrule>
<Lookfor> ~ /Showarticle. aspx \? Id = (\ D +) </lookfor>
<Sendto> <! [CDATA [~ /Show. aspx]> </sendto> <! -- Here -->
</Rewriterrule>
Everything is okay. This address can be accessed.
Http://www.aspxboy.com/ShowArticle.Aspx? Id = 214
:-)