Url Rewriting in asp.net but maintaining the original url

老子叫甜甜 提交于 2019-12-19 17:42:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3678371/url-rewriting-in-asp-net-but-maintaining-the-original-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!