How to read the rewritten url. If I don't use .aspx in my rewritten url then 'Request.RawUrl' is not working. It is returning the original URL.
Please suggest if you have any solution to this. I am using Ionics Isapi Rewrite Filter (IIRF).
For example, if I have rewrite:
http://<mywebsite>/users.aspx?id=12&name=amitava
to
http://<mywebsite>/profile/12/amitava
Now in the same page, at some point, I want to get this rewrittern url for the purpose of pointing return url in login link. Now a login link should be:
http://<mywebsite>/login.aspx?ReturnUrl=/profile/12/amitava
or
http://<mywebsite>/login.aspx?ReturnUrl=http://<mywebsite>/profile/12/amitava
What is the proper way to achieve this? Thanks.
For IIRF, this is called unmangling and can be achieved by using the modifier U
.
From the IIRF manual:
U = Store original url in server variable HTTP_X_REWRITE_URL
Simply add the modifier U
to the RewriteRule
for which you would like to retain the original url. For example:
RewriteRule ^yourexpression$ yourrewrittenurl [I,U,L]
Then, in the code of your page, you may access the original url like this:
Request.ServerVariables("HTTP_X_REWRITE_URL")
See also my answer here