Request.UrlReferrer is null, what gives?

Request.UrlReferrer is null, what gives?


I was looking for a consistent way to be able to know the url a user was coming from when loading a page. I came across the Request.UrlReferrer property of the page, and thought “hey, this is exactly what I need!”, but that wasn’t the case. It was working in some instances, and was coming up null in other instances, I wasn’t sure exactly what causing the null value so I did a little research. Basically this referrer property is optionally set by the browser, and should never really be relied on to be consistent.

From “gopalanmani” lays it out pretty clearly. Thanks!

The situations where it does work include the following methods of a browser loading a URL:

  • clicking on a straight HTML <a href> link;
  • submitting a form, using POST or GET, from a submit button, <input type=image> or client-side script (form.submit())

The situations where it doesn’t work:

  • using Response.Redirect / Server.Transfer;
  • clicking on a Favorite, History, or the recently-typed URLs list;
  • clicking on ‘Home’ in IE’s toolbar, or an item in IE’s ‘Links’ toolbar;
  • using location.href or location.replace() in client-side JScript/JavaScript/VBScript;
  • using HierMenus (details);
  • typing the URL directly in the browser and hitting Enter or clicking ‘Go’;
  • launching a clickable URL from an e-mail or MS Office document;
  • using Response.AddHeader  or <meta http-equiv=refresh> to redirect;
  • loading the URL with XML


So basically, beware when using this property. Depending on what browser is being used, and how the user came to the page, this property may not be consistently set.

By |2018-06-27T17:47:25+00:00December 4th, 2011|Categories: ASP.NET|Tags: |1 Comment

About the Author:

One Comment

  1. kyle June 14, 2018 at 1:20 pm - Reply

    I use that to forbid a keyboard URL input (or by copy / paste).

    Dim MyUrl As HttpRequest = Request

    If IsNothing(MyUrl.UrlReferrer) Then
    ‘ put a redirection to an error page

Leave A Comment