Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the HTTP Referrer in ASP.NET

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.

like image 773
Chuck Le Butt Avatar asked Nov 23 '10 16:11

Chuck Le Butt


People also ask

How do I get referer from HTTP request?

It's available in the HTTP referer header. You can get it in a servlet as follows: String referrer = request. getHeader("referer"); // Yes, with the legendary misspelling.

What is URL referrer in asp net?

http referrer indicates the previous page that has submitted data or linked to the new page. you can get it in ASP.NET using like. C# Copy Code. //PageName comes from HttpContext.Current.Request.RawUrl and is supplied by the Page_Load event.

Why is HTTP referer empty?

There might be several reasons why the referer URL would be blank. It will/may be empty when the enduser: entered the site URL in browser address bar itself. visited the site by a browser-maintained bookmark.


1 Answers

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).

like image 164
Darin Dimitrov Avatar answered Sep 19 '22 17:09

Darin Dimitrov