Losing Session on Page Load and Postback

I have an app that has been working just fine to date, but recently started dropping session.
I have enclosed the error messages I am getting, but do not know what to make of them.
The errors happen on page_load after leaving my login page or on postback.

Object cannot be cast from DBNull to other types.


Operator '<>' is not defined for type 'DBNull' and type 'DBNull'.

Here is the page load event on the default page:

   If Request.QueryString("LostSession") = "True" And Not IsPostBack Then
            Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "SessionWarning", "alert('Your session was lost.');", True)
        End If

Here is the page load event on the second page:

    If IsNothing(Session("id")) Or Not IsNumeric(Session("id")) Then
            Response.Redirect("default.aspx?LostSession=True", True)
        End If
Who is Participating?
Alfred A.Connect With a Mentor Commented:
----> I have an app that has been working just fine to date, but recently started dropping session.

First of all, did you have a sudden increase with the number of users concurrently hitting your web site?

Did you enhanced your web application by adding heavier processing such as heavier SQL queries, heavier coding logic, and heavy session use?

What session management are you currently using InProc, State Server, or SQL Server?

If your answer in my first two questions is "yes" and your session management is InProc, then there is a possibility that this is the reason for the session droppings.  I encountered this type of problem before where we always get different types of error that we cannot even understand why it is happening.  When I changed my heavy web application before to "State Server" most of the object problems I was encountering disappeared!

I hope this helps.

OK since the web server is all OK try a few of the following steps  before you can narrow this down.

Make sure your server is correctly working I.e no one has changes you network setting, firewall and check your exception tab.

I would check for the following, make sure your switches a functioning OK, check that no one has put a telephone cable back into a the switch .

If you have a WAN step up check that your bridgehead serve is working correctly.

Try to ping and trace route to the a extremal address when this occurs or try GFI network  monitor and keep pinging the server and switch and router to see if you are getting drop outs.

Make sure your DNS setting and DHCP are all set up correctly and that your site trust are correctly working.

devnewbeeAuthor Commented:
This fixed my issue.  Thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.