473,569 Members | 2,799 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()=="A dd")
{
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 1332
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()=="A dd")
{
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******** ******@TK2MSFTN GP09.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()=="A dd")
{
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******** ******@TK2MSFTN GP10.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()=="A dd")
{
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
14642
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 hits a submit button, which then takes the user to a 2nd PHP page which simply runs PHP code that checks the user's credentials from my database,...
6
3458
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) Case "Authenticated" Case "CI_CODE" Case "organisation_description" Case "location_description"
4
1686
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 response.redirect to the home page. this works for on the normal site, but session state info is dying on the demo subdomain. i'm sure the session info is being...
2
1971
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, logging in as root and running poweroff to close EVERYTHING down. All I really wanna do is terminate the hung console session. Can I do that from the...
9
2444
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 at http://www.lamartin.com/dotnet/sessiontestset.aspx, were I set Session, Application and Cache variables on the first page and then on the second...
5
2660
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 until session expires. iframe.aspx loads and session still has 15 minutes left. Is this possible? I was trying to grab session.timeout at the...
1
3157
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" Response.Redirect("./AnewPage.aspx") ======= If I go, Response.Write(Session("MyName")) in the new page the session variable does not exist.
3
3433
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 session object (using state service). I'd like to start breaking out our functionality into component projects, but I'd like to get this session...
3
2384
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 identify a session using V$SESSION and kill it (using ALTER SYSTEM KILL SESSION ‘SID’). By killing a session, kills all the processes ? Or am I...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.