Why does Context.RewritePath support query string?

After looking at the code below, I noticed that the call Context.RewritePath

somehow does not lose the query string, even if it is without a query string. Is there any documentation to explain why the query string is supported?

//URL relative path to ashx files is wrong to to path rewriting.
if (Request.Url.LocalPath.EndsWith(".ashx")) {
    Context.RewritePath(Request.Url.LocalPath
        .Substring(Request.Url.LocalPath.LastIndexOf("/") + 1));
}

      

Edit: I am not asking how to fix this; the code behaves correctly. I'm just asking for documentation about this behavior.

+3


source to share


1 answer


You are essentially doing a rewrite of the path, and in most cases the query needs to be saved to navigate to the new path.

Take, for example, a new document search page named "getDocumentWithEnhancements.aspx" as opposed to the old "getDocument.aspx". Both require the parameter to be useful, but you want the new one to be used. RewritePath would do the job, since it would pass the request passed to the old one and go to the new one. If you want to show some kind of error page or something, you either use a redirect instead, or whatever page you rewrite, just ignore the request.



Why don't you want the request to go through? What exactly are you using it for? It might not be the right function for what you need.

edit: there is an overloaded function that takes 3 parameters, one of which is a request, which you can pass as null to avoid using the request.

0


source







All Articles