Is There a Current Session?

J

Johnson

In a centralized error logging routine I need to determine whether there is
a "current session" - then if there is I log some information stored in the
current session. I have an HTTP Module that logs all otherwise unhandled
exceptions. Sometimes it logs exceptions that apparently are not related to
any particular Session (perhaps they occur before a new Session is
established).

So, I need a line of code that answers the question - "is there a current
session?"

I have this now:
if (System.Web.HttpContext.Current.Session["someVariable"] != null) {
// log stuff about the current Session here
}

BUT it chokes periodically with the exception message, "Object reference not
set to an instance of an object.".

Any suggestions?

Thanks!
 
P

Patrice

I would try to test first if System.web.httpContext.Current.Session is null
?

Patrice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top