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?

Edited by shaqtus: n/a

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by PsychoCoder
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.";
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.