mike55 Posted October 18, 2006 Posted October 18, 2006 (edited) Hi all I am using the following cmd in the post-back section of my page to identify what page I came from. Here is the code that I am using: If Not Page.IsPostBack Then ViewState("ReferenceURL") = Request.UrlReferrer.ToString end if I am however getting the following error: "Object reference not set to an instance of an object". I can't understand what is causing the error, as when the page is called from another page it works perfectly. Any suggestions? I have a sample application using the smae code and there is no problem. Could it be anything to do with the fact that I am using the asp.net 2.0 menu control to redirect the user? Mike55. Edited October 18, 2006 by mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted October 18, 2006 Administrators Posted October 18, 2006 You would just need to check if Request.UrlReferer is nothing before trying to convert it to a string, if you haven't been referred then it won't be set. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mike55 Posted October 19, 2006 Author Posted October 19, 2006 My question then is, why does the Request.UrlReferer have a value some times and not other times? Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
scaldwe Posted October 27, 2006 Posted October 27, 2006 The UrlReferer is only valid or will have value when coming from or being "referred" by another page. So if a visitor hits your site from a desktop shortcut, favorites item, or typing in the url in the address bar, or anything of that nature there will be no referer to track in session. Now if you click on a link from another page ... then that page will become the referer page. If you have issues with it throwing exceptions I stop it by having a global static class function in most apps to take care of it like this .... public static String QString(String paramName) { String tmpS = String.Empty; try { tmpS = HttpContext.Current.Request.ServerVariables[paramName].ToString(); } catch { tmpS = String.Empty; } return tmpS; } Hope this helps .... Quote
dinoboy Posted November 3, 2006 Posted November 3, 2006 In addition, some browsers or other settings may disallow HTTP refferes. So even when the page shouldn't be accessible without a reffere, you should check if the refferer is set. I just had the same problem, because my Firefox didn't set refferer. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.