Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by mike55

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)

Posted

My question then is, why does the Request.UrlReferer have a value some times and not other times?

 

Mike55.

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)

  • 2 weeks later...
Posted

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 ....

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...