HttpContext.Current.Session is throwing exception(Object reference not set to an inst

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SujaShyam
    New Member
    • Sep 2010
    • 2

    HttpContext.Current.Session is throwing exception(Object reference not set to an inst

    In our application we have to access session objects in business class. We are using HttpContext.Cur rent.Session to get the session value. In some cases it returns the value but mostly its throwing a null reference exception(Objec t reference not set to an instance of an object). We have the following code
    Try

    If HttpContext.Cur rent.Session("U sername") IsNot Nothing then
    ' Statements to be executed
    End If
    Catch ex As Exception
    'Log to db
    End Try

    Here HttpContext.Cur rent.Session("U sername") is mostly throwing an exception "Object reference not set to an instance of an object"
    While debugging we found that HttpContext.Cur rent itself is nothing.

    Thanks. Any help on this will be appreciated.
Working...