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?

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.";
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.