I have the following code:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.UrlReferrer.Host != "www.test.com")
{
Response.Redirect("~/redirect.aspx");
}
}
My goal is, that page cannot be accessible if it is visited from a URL other than the one in the if statement however when I run my project I am getting the following error: An exception of type 'System.NullReferenceException' occurred
Why there is a NUll exception? if it is null it should just execute my code that Ihave inside Page_Load... Please advise if there is another way to do what I am attempting, or if there is a way I can handle the Null Exception Error. Thank you.