views:

52

answers:

2

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

If HttpContext.Current.Session("Username") IsNot Nothing then ' Statements to be executed End If Catch ex As Exception 'Log to db End Try

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

Thanks. Any help on this will be appreciated.

A: 

HttpContext is usually not available in Business layer. You usually pass it as an argument from your code-behind pages. Are you doing that correctly?

Sidharth Panwar
A: 

We are able to access HTTPContext in busines classes. In our case mostly HttpContext.Current is nothing.

Suja
this should really be a comment (for future reference)
Antony Scott