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();
}