1.11M Members

Request.UrlReferrer

 
0
 

This code is in the Page_Load method of my web page.

if (Request.UrlReferrer.AbsolutePath == "/Home/Default.aspx")
{
    Label1.Text = "You are coming from the home page.";
}

When I try to open the page, I get this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

The error occurs at the line marked in red in the code. I don't know how to fix it... help anyone please?

 
0
 

That's happening because when you just open that page it doesnt have a referrer. You need to make sure it's not null before checking it

if (!Request.UrlReferrer.AbsolutePath == null)
{
    if (Request.UrlReferrer.AbsolutePath == "/Home/Default.aspx")
    {
        Label1.Text = "You are coming from the home page.";
    }
}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article