Request.UrlReferrer is null, what gives?

Request.UrlReferrer is null, what gives?

 

ConfusedI 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 http://forums.asp.net/t/1097333.aspx/1 “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-03-07T02:50:36+00:00 December 4th, 2011|Categories: ASP.NET|Tags: |0 Comments

About the Author:

Leave A Comment