2010-09-09 51 views
7
Page aspxHandler = (Page)PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context); 

aspxHandler.PreRenderComplete += AspxPage_PreRenderComplete; 
aspxHandler.ProcessRequest(context); 

当你经过此事致电Page.Request.Url,你得到你要改写了URL重写在asp.net但保持原始地址

页面的网址...我在寻找什么因为是做一个重写,但是让Page.Request.Url保持原来的URL传递。这可能吗?

回答

10

我有一个类似的问题,在web.config中使用重写规则。不知道这是否也能解决您的问题,但我发现当重写URL时,最初请求的URL可通过“HTTP_X_ORIGINAL_URL”服务器变量访问。

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; 

这应该让你请求的原始路径和查询字符串重写之前,不论是否重写已经发生。

+0

正是我在找的东西。谢谢! – 2010-12-23 01:55:14

+0

谢谢,福尔摩斯。 +1 – 2012-04-19 18:39:00

+0

请注意,AllKeys是一个数组,并且不提供Contains方法 – 2015-06-22 14:12:31