Akanksha Singh Akanksha Singh - 1 month ago 18
Vb.net Question

Request.UrlReferrer is coming as null on page refresh

Can anyone tell me how I can modifiy the code when on refreshing the page value of Request.UrlReferrer is coming as null.Actually it is throwing as exception.I have to handle this exception.Any idea anyone??


UrlReferrer can't be controlled by your server side code - it just exposes value sent by browser/client along with request. There are plenty of cases that value is not present (initial request/refresh, HTTP/HTTPS transition) so your code must be able to handle this case.

At very least you just need to check for null (you may also need to handle UriFormatException if you need to handle requests from rogue clients in a nice way):

  if (Request.UrlReferrer != null)
       // run your code that deals with referrer