The usual use scenario is when we have a page that requires a user to log in to access, we will in the code to determine whether the current access user is logged in, if not logged in, then redirect to the login page, and the current URL through the URL parameter passed to the login page. If you use a URL rewrite, and get the current URL through the Request.Url.AbsoluteUri, the user is logged on after the rewrite of the address, which does not affect the normal use, but from the user experience and the unity of the Url point of view, we would prefer to be rewritten before the address.
Before, we are also in the development of this problem, only as far as possible through JS redirect to the login page (through Location.href to get the current URL) or in the code manually write return address.
Now we've found a workaround where we can find the rewritten URL from the request.headers.
1 if the overriding component is isapi_rewrite, then when accessing the overridden URL, an additional data will be added to the headers: key is X-rewrite-url and the value is the URL before the rewrite.
2 If the overriding component is a URL rewrite module with IIS, the key to the added information in headers is x-original-url.
So we can easily get the URL before the rewrite, the sample code is as follows:
Copy Code code as follows:
if (request.headers["X-rewrite-url"]!= null)
{
Response.Write ("http://" + Request.Url.Host + request.headers["X-rewrite-url"]);
}
else if (request.headers["X-original-url"]!= null)
{
Response.Write ("http://" + Request.Url.Host + request.headers["X-original-url"]);
}