Getting the HTTP Referrer in ASP.NET

Chuck Le Butt picture Chuck Le Butt · Nov 23, 2010 · Viewed 189.2k times · Source

I'm looking for a quick, easy and reliable way of getting the browser's HTTP Referrer in ASP.Net (C#). I know the HTTP Referrer itself is unreliable, but I do want a reliable way of getting the referrer if it is present.

Answer

Darin Dimitrov picture Darin Dimitrov · Nov 23, 2010

You could use the UrlReferrer property of the current request:

Request.UrlReferrer

This will read the Referer HTTP header from the request which may or may not be supplied by the client (user agent).