开发者

How to get original url after HttpContext.RewritePath() has been called

开发者 https://www.devze.com 2022-12-22 20:49 出处:网络
I am working on a web app which makes 开发者_如何学编程use of a 3rd party HttpModule that performs url rewriting.

I am working on a web app which makes 开发者_如何学编程use of a 3rd party HttpModule that performs url rewriting.

I want to know if there's any way to determine the original url later on in Application_BeginRequest event. For example...

Original url:

http://domain.com/products/cool-hat.aspx

Re-written url (from 3rd party httpmodule):

http://domain.com/products.aspx?productId=123

In the past I have written HttpModules that store the original url in HttpContext.Items but, this is a 3rd party app and I have no way of doing that.

Any ideas would be appreciated.


Try this:

string originalUrl = HttpContext.Current.Request.RawUrl;

The original URL is inside of this property.


I had the same problem, but I wanted the fully qualified URL (RawUrl gives you just the Path and Query part). So, to build on Josh's answer:

string originalUrlFull = 
   Page.Request.Url.GetLeftPart(System.UriPartial.Authority) + 
   Page.Request.RawUrl


I know this question was asked long time ago. But, this is what I use:

System.Uri originalUri = new System.Uri(Page.Request.Url, Page.Request.RawUrl)

Once you have the URI you can do a ToString() to get the string, or cal any of the methods/properties to get the parts.


Create a new HttpModule to serve as a wrapper around (inherits) the third party module and do whatever you want with it.

In your case, override the appropriate function (ProcessRequest?) and store the original url in HttpContext.Items, and then call the MyBase implementation. Should work fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消