Wednesday, March 26, 2008

Request.UrlReferrer could be null

The Request.UrlReferrer is the client's previous request that has linked to the current URL. The URLs don't necessarily need to be in the same domain. Even if it's in a separate domain, the client's current URL will be sent to the other page as the client's current URL address.

So let's say you've been redirected to the other page, Request.UrlReferrer gets the client's previous URL. If the client is a browser, and you refresh (for example F5), the server request still has the client's previous URL. There is one exception. If, in the browser address bar, you click on the Go button beside it, this new server request has the Request.UrlReferrer as null. This is why the code-behind needs to check for nulls when accessing the Request.UrlReferrer object.

Another way of getting to UrlReferrer is: Request.ServerVariables["HTTP_REFERER"];

Considerations: Proxies may remove the referrer information.

0 comments: