Referer in Request Header
I have a page which I do not want to the user to access directly by typing the hyperlink. If the user directly accesses the page, I want to display a 500 Internal Server Error
The Request header has a key called Referer. This key contains the URL from which the user has come to the page. If the user clicked on a link in Page1 and came to Page2, the Referer header in Page2 will contain the URL of Page 1. Here is some code:
string referer = Request.Headers["Referer"]; if (String.IsNullOrEmpty(referer)) { Response.Clear(); Response.Status = "500 Internal Server Error"; Response.StatusCode = 500; Response.End(); }
Posted by Vijay on 15-Oct-2009 12:55 AM
Category : ASP.NET
Category : ASP.NET
Commented by
rtpHarry
at 15-Oct-2009 09:47 AM
Just so you know - certain firewalls and security software clears the referrer field - http://en.wikipedia.org/wiki/HTTP_referrer#Referrer_hiding


