Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url Rewriting in asp.net but maintaining 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 this, you get the Url of the page you rewrote to

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

like image 671
Paul Avatar asked Sep 09 '10 16:09

Paul


1 Answers

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

VB:

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

c#:

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

That should get you the original path and querystring of the request before rewriting, whether or not rewriting has taken place.

like image 123
Charlie Avatar answered Sep 28 '22 01:09

Charlie