Url Rewriting in asp.net but keeping the original url

Page aspxHandler = (Page)PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context); aspxHandler.PreRenderComplete += AspxPage_PreRenderComplete; aspxHandler.ProcessRequest(context); 

When you call Page.Request.Url after that, you get the url of the page that you rewrote to

... what I'm looking for is to rewrite, but for Page.Request.Url to remain as the original URL that was passed. Is it possible?

+7
url-rewriting
source share
1 answer

I had a similar problem using rewrite rules in web.config. Not sure if this will solve your problem either, but I found that when the URL was rewritten, the originally requested URL was accessible through the server variable HTTP_X_ORIGINAL_URL.

VB:

  string pathAndQuery = Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL") ? Request.ServerVariables("HTTP_X_ORIGINAL_URL") : Request.Url.PathAndQuery 

FROM#:

  string pathAndQuery = Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL") ? Request.ServerVariables["HTTP_X_ORIGINAL_URL"] : Request.Url.PathAndQuery; 

This should give you the source path and query request before rewriting whether the rewriting has occurred.

+10
source share

All Articles