Thursday, March 29, 2012

Object Reference error

I have a live ASP.NET site that in general runs very well. However, I am trapping errors and having the error message emailed to me. Everything will run fine but then sporadically, I will receive the following message:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] MeetMarket3.SideBar.Page_Load(Object sender, EventArgs e) System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +750

Request URL: /sidebar.aspx

User:656
ScreenName:2lookingtoplay
Last SQL:exec dbo.spStateList

I am using Cookies to store the UserID and it appears as though this cookie information will get lost. Is there anything that could happen to cause Cookies to get reset?

Greg

There are a number of reasons ranging from why cookies get lost, including the user clearing them out or the plain old fact that they just expire. You must always code defensively when reading from cookies, query strings, form variables and so forth, which means that you must always check to see if the item is null/Nothing before you read from it.

Thanks.

I know that the user is not clearing them as this has happened to me while on the site.

I was under the empression that if you did not set an expiration that they would be valid at least throughout the current browser session. Is that not true?

Greg

0 comments:

Post a Comment