jes*_*vin 14 asp.net url-rewriting httpmodule
我正在开发一个Web应用程序,它使用第三方HttpModule执行URL重写.
我想知道以后是否有任何方法可以在Application_BeginRequest事件中确定原始URL .例如...
原始网址:
http://domain.com/products/cool-hat.aspx
重写网址(来自第三方httpmodule):
http://domain.com/products.aspx?productId=123
在过去,我编写了HttpModules,它将原始url存储在HttpContext.Items中,但是,这是第三方应用程序,我无法做到这一点.
任何想法,将不胜感激.
Col*_*ame 27
试试这个:
string originalUrl = HttpContext.Current.Request.RawUrl;
Run Code Online (Sandbox Code Playgroud)
原始URL位于此属性中.
我有同样的问题,但我想要完全限定的URL(RawUrl只提供路径和查询部分).所以,以Josh的答案为基础:
string originalUrlFull =
Page.Request.Url.GetLeftPart(System.UriPartial.Authority) +
Page.Request.RawUrl
Run Code Online (Sandbox Code Playgroud)
小智 6
我知道很久以前就问过这个问题.但是,这就是我使用的:
System.Uri originalUri = new System.Uri(Page.Request.Url, Page.Request.RawUrl)
Run Code Online (Sandbox Code Playgroud)
获得URI后,您可以执行ToString()来获取字符串,或者调用任何方法/属性来获取部分.
创建一个新的 HttpModule 作为第三方模块的包装器(继承),并用它做任何你想做的事情。
在您的情况下,重写适当的函数(ProcessRequest?)并将原始 url 存储在 HttpContext.Items 中,然后调用实现MyBase。应该可以正常工作。