I am using the following line of code to check if the UrlReferrer
is null
@if (Request.UrlReferrer.AbsolutePath == null)
It just gives me an error of:
System.NullReferenceException: Object reference not set to an instance of an object.
I'm new to asp and have hunted around but can't seem to find anything that will answer my question. The thing that confuses me is if I replace null like so:
@if (Request.UrlReferrer.AbsolutePath == "/Home")
...and the AbsolutePath is indeed /Home, the code works fine, surely I'm asking for the same thing here but with null
?
Request.UrlReferrer is null if there is no referrer, which makes your reference to Request.UrlReferrer.AbsolutePath (a property on a null object) throw a null reference exception.
Instead, try;
@if (Request.UrlReferrer == null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With