Hi all,
I am using a Session object in my ASP.Net application to store a value of
a Database field. I can access it as ...
int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session expires,
would the above statement produce any exception? If I can't find the
ProposalId value in the session object, I would like to display a message to
the user and close the window.
Thanks.
-Nikhil 7 1525
int iProposalId = Session["ProposalId"];
you could then test: IsNothing(iProposalId)
"Nikhil Patel" <ni********@aol.com> wrote in message news:uO**************@TK2MSFTNGP11.phx.gbl... Hi all, I am using a Session object in my ASP.Net application to store a value of a Database field. I can access it as ... int iProposalId = Session["ProposalId"]; The session timeout is set to 20. Now my question is if the session expires, would the above statement produce any exception? If I can't find the ProposalId value in the session object, I would like to display a message to the user and close the window. Thanks. -Nikhil
Are you using any authentication? If you are then have that redirect to the
login page if it's expired, that's what it's designed for. If you aren't
just run a check
if(Session["blah"] is null)
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Nikhil Patel" <ni********@aol.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl... Hi all, I am using a Session object in my ASP.Net application to store a value of a Database field. I can access it as ... int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session expires, would the above statement produce any exception? If I can't find the ProposalId value in the session object, I would like to display a message to the user and close the window.
Thanks. -Nikhil
Hi,
It will return null if the specified key doesn't exist in the session.
if (Session["ProposalId"] is null)
{
// Session expired.
}
else
{
// Parse
}
"Nikhil Patel" <ni********@aol.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
Hi all,
I am using a Session object in my ASP.Net application to store a value of
a Database field. I can access it as ...
int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session expires,
would the above statement produce any exception? If I can't find the
ProposalId value in the session object, I would like to display a message to
the user and close the window.
Thanks.
-Nikhil
As a side note, you could see this as "handling the session timeout" rather
than just this particular value. If I remember a property of the session
object allows to test expiration...
Patrice
--
"Thomas Dodds" <th*********@hotmail.com> a écrit dans le message de
news:OO**************@TK2MSFTNGP11.phx.gbl...
int iProposalId = Session["ProposalId"];
you could then test: IsNothing(iProposalId)
"Nikhil Patel" <ni********@aol.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl... Hi all, I am using a Session object in my ASP.Net application to store a value
of a Database field. I can access it as ... int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session
expires, would the above statement produce any exception? If I can't find the ProposalId value in the session object, I would like to display a message
to the user and close the window.
Thanks. -Nikhil
"Nikhil Patel" <ni********@aol.com> wrote in message news:uO**************@TK2MSFTNGP11.phx.gbl... Hi all, I am using a Session object in my ASP.Net application to store a value of a Database field. I can access it as ... int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session expires, would the above statement produce any exception? If I can't find the ProposalId value in the session object, I would like to display a message to the user and close the window.
Thanks. -Nikhil
If you are using C# then your statement shouldn't work: as Session
returns an object, you can't store it in an int. Solution: cast to int.
But: if that value doesn't exist (anymore) in the Session, you would
get a null value. You can't cast that to an int.
So your code should probably look like:
int iProposalId;
if (Session["ProposalId"] != null)
{
iProposalId = (int)Session["ProposalId"];
}
else
{
// show some alert ...
}
Hans Kesting
> The session timeout is set to 20. Now my question is if the session
expires, would the above statement produce any exception? If I can't find the
It would throw a NullReferenceException. Rather than trying to catch the
exception, which is costly, why don't you check to see whether it is null
first?
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Nikhil Patel" <ni********@aol.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl... Hi all, I am using a Session object in my ASP.Net application to store a value
of a Database field. I can access it as ... int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session
expires, would the above statement produce any exception? If I can't find the ProposalId value in the session object, I would like to display a message
to the user and close the window.
Thanks. -Nikhil
Thank you all.
I use the following statements to check whether the ProposalID exists in
session object.
if (Session["ProposalId"] == null)
this.RegisterClientScriptBlock("Session
Expired","<script>OnSessionExpire()</script>");
else
{
int iProposalID = (int) Session["ProposalId"];
// use iProposalID.........
}
Thanks again.
"Nikhil Patel" <ni********@aol.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl... Hi all, I am using a Session object in my ASP.Net application to store a value
of a Database field. I can access it as ... int iProposalId = Session["ProposalId"];
The session timeout is set to 20. Now my question is if the session
expires, would the above statement produce any exception? If I can't find the ProposalId value in the session object, I would like to display a message
to the user and close the window.
Thanks. -Nikhil
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Martin |
last post by:
Hi all
As my posting title suggests I'm having problems using InProc Session
state in my ASP .NET app.
I wrote a site for a friend which uses ADO .NET to keep track of a
simple...
|
by: Venkat Chellam |
last post by:
I have a peculiar problem. I have a simple web application which loads
some data from the oracle table and display in the datagrid in the
webpage and datagrid has page enabled which shows 10 rows...
|
by: Mike |
last post by:
Hi,
I am developing an application with framesets (header, left navigation, and
content). Each frameset loads an ".aspx" page, and in one of these pages, I
store some information in the Session...
|
by: Alphonse Giambrone |
last post by:
I am building a web app for users to add/edit data. They may add/edit
several records during a session.
When they are done (not necessarily immediately, could be 10 or more minutes
later), I need...
|
by: Chris |
last post by:
I'm on a project where the prevoius developer wrote code like below. I
thought stuff like this was bad? Isn't he putting a page into a session
object? And what we are trying to do is hit the db via...
|
by: Bahman |
last post by:
Hello!
I have a simple question.
Do we have session arrays that we can reference, assign, or select from?
Could I please have a sample of how this is done. The obvious syntax that I
am...
|
by: |
last post by:
Simple question, I think...
I'm storing an object in the Session object.
In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction)
If I change any...
|
by: Ned Balzer |
last post by:
Hi,
Apologies if this is a newbie question, I haven't found the answer in
any faqs.
I have an asp.net 2.0 page that sets session variables and then
redirects to another page. For the page...
|
by: Cirene |
last post by:
In my web.config I added <pages enableSessionState="true">.
In each of my pages I also added EnableSessionState="True" to the Page
declaration.
(I didn't think this was necessary, but...)
...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |