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 1553
int iProposalId = Session["ProposalId "];
you could then test: IsNothing(iProp osalId)
"Nikhil Patel" <ni********@aol .com> wrote in message news:uO******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP11.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*********@ho tmail.com> a écrit dans le message de
news:OO******** ******@TK2MSFTN GP11.phx.gbl...
int iProposalId = Session["ProposalId "];
you could then test: IsNothing(iProp osalId)
"Nikhil Patel" <ni********@aol .com> wrote in message
news:uO******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP11.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 NullReferenceEx ception. 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******** ******@TK2MSFTN GP11.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.RegisterCl ientScriptBlock ("Session
Expired","<scri pt>OnSessionExp ire()</script>");
else
{
int iProposalID = (int) Session["ProposalId "];
// use iProposalID.... .....
}
Thanks again.
"Nikhil Patel" <ni********@aol .com> wrote in message
news:uO******** ******@TK2MSFTN GP11.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 customer/purchases database. A user creates an account and a
database entry is added to a customer table. Once a user successfully
logs in with a valid Username/Password I store away the UserID (which
is the primary key of the Customers table) in the Session...
|
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 at a page.I
have a search criteria to search the records based on the data range i
give
This is what i have done, in the !IsPostBack section. I am setting up
the oracle connection, creating dataset object, datadapter and i aslo
load the data...
|
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 object, as follows:
....
Session = false;
....
|
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 to send an email with some summary info of what was
added/edited.
I can keep track of the records by using the sessionid or user's login, but
how can I determine when to send the email and who the user was since there
is no session info available...
|
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 a Stored Proc to
create a datatable in most cases. This seems like a waste to me. Is this good?
Public Shared Function getSQL(ByRef thePage As Page) As ProjectName.SQLServer
If thePage.Session("mySQLInit") = "1" Then
Return...
| |
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 trying doesn't work. There are SA's in VB, but I am not seeing anything
for C#.
|
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 properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object?
Thanks,
Jerry
|
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 that gets redirected to, I've
swapped in a simple page for testing that reads the session variables
and displays their values.
|
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...)
Any reason why even though I did this I keep getting this error....
Server Error in '/abc' Application.
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |