473,509 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is There a Current Session?

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!
Nov 19 '05 #1
1 1308
I would try to test first if System.web.httpContext.Current.Session is null
?

Patrice

--

"Johnson" <JM**@SpamThis.com> a écrit dans le message de
news:Oh**************@tk2msftngp13.phx.gbl...
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!

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3314
by: moondaddy | last post by:
I need to set a variable to a session variable (if that's what you call it) like this: dim ds as dataset = HttpContext.Current.Session("CustDataSet") But I get an exception if this variable...
15
1860
by: SFX | last post by:
If I have a session ID (string) can I somehow obtain the session object associated to that ID (it exist of course) ? I know this sounds wicked but I have a situation in which I have to make a...
15
2464
by: Jason | last post by:
Currently, I am storing information about the currently logged on user in Session variables that are stored in SQL. However, I am using role-based security, so I am storing custom roles in a...
2
1859
by: midgetgem | last post by:
I'm storing a DataTable in a session object and call a seperate class with a method in it to work with. How do I access the session from this class? I was using HttpContext.Current.Session,...
6
26293
by: vijayk | last post by:
Hi all, I have a field which has data as YYYYMMDD, and I have to find the age of the person by substracting it from current date. can you please please advice... thanks
4
1515
by: Jon Paal | last post by:
I captured an arraylist into a session value but to display the current values, the page requires a postback or else it displays the prior version of the value. how do I force a post back...
2
11932
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined...
14
29418
by: R.A.M. | last post by:
Hello, I have created ASP.NET project in which I have a file Admin.cs. It contains static class Admin with some methods and properties. The problem is that in property get a reference...
3
8874
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.