Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request.UrlReferrer.ToString() ->System.NullReferenceException: Object reference not set to an instance of an object

Tags:

c#

asp.net

When I try Request.UrlReferrer.ToString() this error occures:

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

like image 406
user1625764 Avatar asked Aug 29 '12 23:08

user1625764


1 Answers

You have to check if UrlReferrer is null, as it's not always set (ie, when someone typed the URL directly into the address bar, or clicked on a bookmark)...

(Request.UrlReferrer == null) ? "" : Request.UrlReferrer.ToString()
like image 181
McGarnagle Avatar answered Oct 21 '22 08:10

McGarnagle