Generally, when a user logs on to a page, we can determine in the Code whether the current user is logged on. If the user is not logged on, we will redirect to the logon page, and pass the current Url to the logon page through Url parameters. If URL rewriting is used and Request is passed. url. absoluteUri obtains the current website address. After a user logs on, the address is the rewritten address, which does not affect normal use. However, from the perspective of unified user experience and URL, we prefer to rewrite the previous address.
Previously, we were also troubled by this problem during development. We could only try to redirect to the login page through js (get the current URL through location. href) or manually write the return address in the code.
Now, we have found a solution. You can find the URL before rewriting in Request. Headers.
1) if the Rewrite component uses ISAPI_Rewrite, a data entry will be added to Headers when the accessed URL is overwritten: Key is X-Rewrite-URL, and the value is the previous URL.
2) If the Rewrite component uses the built-in iis url Rewrite module, the Key of the added information in Headers is X-Original-URL.
In this way, you can easily obtain the URL before rewriting. The sample code is as follows:
Copy codeThe Code is 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"]);
}