473,503 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session is killing Me ?

Hi,

am in c#.net project.

am using the session object for some logic.
e-g:session["Mode"]="Add";
i can refer this by using
if(Session["Mode"]=="Add")
{
logic
}

It is working nice for some moment.later on ,it will tell the error
like(in if statement)
------------------------------------------
'object referrence not set to an instance of an object'
------------------------------------------------------
if i change the 'if' statement as

if(Session["Mode"].Tostring()=="Add")
{
logic
}

it is working nice for some moment . and again tells the same error .So
iam keep on changing between the statements as
i given above & get working.

Why it is killing Me like that.What is the exact statement / Have i to
include something ?
Please help me

With thanks
a drop in the ocean.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
3 1322
Raghu Raman wrote:
Hi,

am in c#.net project.

am using the session object for some logic.
e-g:session["Mode"]="Add";
i can refer this by using
if(Session["Mode"]=="Add")
{
logic
}

Does this even compile? Session["Mode"] should return an Object.
If it is possible to compare with a string, then the result could be unexpected.
It is working nice for some moment.later on ,it will tell the error
like(in if statement)
------------------------------------------
'object referrence not set to an instance of an object'
------------------------------------------------------
if i change the 'if' statement as

if(Session["Mode"].Tostring()=="Add")
{
logic
}

What if there is no ' Session["Mode"] ' ? It would return null then,
and null.ToString() will give that exception.
Solution: use this check:
if (Session["Mode"] != null && Session["Mode"].ToString() == "Add")
.....
it is working nice for some moment . and again tells the same error
.So iam keep on changing between the statements as
i given above & get working.

Why it is killing Me like that.What is the exact statement / Have i to
include something ?
Please help me

With thanks
a drop in the ocean.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2
First of all you should follow what Hans Kesting said about checking for the
existence of the Session variable. Now, if you are losing your session data
after sometime, then you got a bigger problem. Try to debug and find out if
Session_End event handler is firing before your session timeout occurs.
There can be so many reasons why that could happen. So, first try to figure
out if your session is dying before the timeout occurs

--
Kumar Reddi
http://kumarreddi.blogspot.com

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
Raghu Raman wrote:
Hi,

am in c#.net project.

am using the session object for some logic.
e-g:session["Mode"]="Add";
i can refer this by using
if(Session["Mode"]=="Add")
{
logic
}

Does this even compile? Session["Mode"] should return an Object.
If it is possible to compare with a string, then the result could be

unexpected.
It is working nice for some moment.later on ,it will tell the error
like(in if statement)
------------------------------------------
'object referrence not set to an instance of an object'
------------------------------------------------------
if i change the 'if' statement as

if(Session["Mode"].Tostring()=="Add")
{
logic
}


What if there is no ' Session["Mode"] ' ? It would return null then,
and null.ToString() will give that exception.
Solution: use this check:
if (Session["Mode"] != null && Session["Mode"].ToString() == "Add")
....
it is working nice for some moment . and again tells the same error
.So iam keep on changing between the statements as
i given above & get working.

Why it is killing Me like that.What is the exact statement / Have i to
include something ?
Please help me

With thanks
a drop in the ocean.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 19 '05 #3
Sessions time out, so you should always check for null before trying to work
with any object stored in Session. You should also have a way of restoring
items which are discarded due to timeout.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Raghu Raman" <ra************@rediffmail.com> wrote in message
news:#U**************@TK2MSFTNGP10.phx.gbl...
Hi,

am in c#.net project.

am using the session object for some logic.
e-g:session["Mode"]="Add";
i can refer this by using
if(Session["Mode"]=="Add")
{
logic
}

It is working nice for some moment.later on ,it will tell the error
like(in if statement)
------------------------------------------
'object referrence not set to an instance of an object'
------------------------------------------------------
if i change the 'if' statement as

if(Session["Mode"].Tostring()=="Add")
{
logic
}

it is working nice for some moment . and again tells the same error .So
iam keep on changing between the statements as
i given above & get working.

Why it is killing Me like that.What is the exact statement / Have i to
include something ?
Please help me

With thanks
a drop in the ocean.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #4

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

Similar topics

6
14641
by: Jeff | last post by:
I've searched the web for hours trying to figure out this problem and can't seem to find any pertinent answers. I have a website where the user starts on a login page, puts in their credentials and...
6
3454
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
4
1679
by: Dica | last post by:
we've just set up a subdomain, 'demos' for one of our projects that normally works fine. on the login page, if the user enters the correct username/pw, we write session info and then...
2
1966
by: MLH | last post by:
On the subject of switching between virtual consoles to get out of a 'hung' situation in the primary console... What I have been doing is pressing LEFTALT-F4 to bring up a 2nd virtual console,...
9
2437
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
5
2655
by: Jon Booth | last post by:
I want to write an apsx page that when loaded does not refresh Session.Timeout. It is going to be running in an iframe and refreshing every couple of minutes. example. User has 15 minutes left...
1
3135
by: John | last post by:
Hi, I have a routine that sets some session variables and then redirects the user to another page in the same application/ same folder. ======= Session("MyName") = "Fredsmith"...
3
3428
by: Mark | last post by:
Ok, I know that .net inherently does not share session data across asp.net projects, but is there any decent work around to this. We already have a big chunk of our application using the asp.net...
3
2379
by: eeriehunk | last post by:
Hi All, I am a little confused between a session and a process. I learnt that an Oracle Session is created for every login. And we can run many processes in one session. I have also learnt how to...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
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
7280
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
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
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,...
0
3167
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
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.