473,473 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Check session object?

LL
Hi,

Where is the best place to check the session's object, if it's null, then
redirect the user to login page?

put into every page's load event?

Thanks.
Nov 15 '05 #1
5 10837
LL,

There will always be a session object available to you (or at least,
there should be). The best way to do this would be to set up the web.config
file to deny any unauthorized users. Basically, you place a <deny
users="?"> element in the <authorization> section and it will redirect
unauthorized users to the login page that you specify.

Check out the section of the .NET framework titled "Forms Authentication
Provider", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...onprovider.asp

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"LL" <li*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Where is the best place to check the session's object, if it's null, then
redirect the user to login page?

put into every page's load event?

Thanks.

Nov 15 '05 #2
LL
Thanks Nicholas.

I use "Form Auth" to login. and I still need to store some info in the
Session["xx"] for other pages. How to deal the case: if session expire.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 378: StateIndex["ON"] = 7;
Line 379:
Line 380: if (Session["Lever"] == null)
Line 381: {
Line 382: Response.Redirect("login.aspx");
Source File: c:\project\Test\admin.aspx.cs Line: 380

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:el**************@TK2MSFTNGP12.phx.gbl...
LL,

There will always be a session object available to you (or at least,
there should be). The best way to do this would be to set up the web.config file to deny any unauthorized users. Basically, you place a <deny
users="?"> element in the <authorization> section and it will redirect
unauthorized users to the login page that you specify.

Check out the section of the .NET framework titled "Forms Authentication Provider", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...onprovider.asp
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"LL" <li*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Where is the best place to check the session's object, if it's null, then redirect the user to login page?

put into every page's load event?

Thanks.


Nov 15 '05 #3
Hi LL,

You should always check the session's objects for null before doing
anything with it, if it's null either the previous session expired or the
object has not been created yet.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"LL" <li*******@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
Thanks Nicholas.

I use "Form Auth" to login. and I still need to store some info in the
Session["xx"] for other pages. How to deal the case: if session expire.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 378: StateIndex["ON"] = 7;
Line 379:
Line 380: if (Session["Lever"] == null)
Line 381: {
Line 382: Response.Redirect("login.aspx");
Source File: c:\project\Test\admin.aspx.cs Line: 380

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:el**************@TK2MSFTNGP12.phx.gbl...
LL,

There will always be a session object available to you (or at least,
there should be). The best way to do this would be to set up the

web.config
file to deny any unauthorized users. Basically, you place a <deny
users="?"> element in the <authorization> section and it will redirect
unauthorized users to the login page that you specify.

Check out the section of the .NET framework titled "Forms

Authentication
Provider", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...onprovider.asp

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"LL" <li*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Where is the best place to check the session's object, if it's null, then redirect the user to login page?

put into every page's load event?

Thanks.



Nov 15 '05 #4
LL
Thanks Ignacio.

How to check?
Using this one:
if (Session["Lever"] == null)?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uA**************@TK2MSFTNGP11.phx.gbl...
Hi LL,

You should always check the session's objects for null before doing
anything with it, if it's null either the previous session expired or the
object has not been created yet.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"LL" <li*******@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
Thanks Nicholas.

I use "Form Auth" to login. and I still need to store some info in the
Session["xx"] for other pages. How to deal the case: if session expire.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 378: StateIndex["ON"] = 7;
Line 379:
Line 380: if (Session["Lever"] == null)
Line 381: {
Line 382: Response.Redirect("login.aspx");
Source File: c:\project\Test\admin.aspx.cs Line: 380

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:el**************@TK2MSFTNGP12.phx.gbl...
LL,

There will always be a session object available to you (or at least, there should be). The best way to do this would be to set up the

web.config
file to deny any unauthorized users. Basically, you place a <deny
users="?"> element in the <authorization> section and it will redirect
unauthorized users to the login page that you specify.

Check out the section of the .NET framework titled "Forms

Authentication
Provider", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...onprovider.asp

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"LL" <li*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> Where is the best place to check the session's object, if it's null,

then
> redirect the user to login page?
>
> put into every page's load event?
>
> Thanks.
>
>



Nov 15 '05 #5
Hi,

Yep, that will work ;)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"LL" <li*******@hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
Thanks Ignacio.

How to check?
Using this one:
if (Session["Lever"] == null)?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uA**************@TK2MSFTNGP11.phx.gbl...
Hi LL,

You should always check the session's objects for null before doing
anything with it, if it's null either the previous session expired or the
object has not been created yet.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"LL" <li*******@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
Thanks Nicholas.

I use "Form Auth" to login. and I still need to store some info in the
Session["xx"] for other pages. How to deal the case: if session expire.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 378: StateIndex["ON"] = 7;
Line 379:
Line 380: if (Session["Lever"] == null)
Line 381: {
Line 382: Response.Redirect("login.aspx");
Source File: c:\project\Test\admin.aspx.cs Line: 380

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:el**************@TK2MSFTNGP12.phx.gbl...
> LL,
>
> There will always be a session object available to you (or at least, > there should be). The best way to do this would be to set up the
web.config
> file to deny any unauthorized users. Basically, you place a <deny
> users="?"> element in the <authorization> section and it will
redirect > unauthorized users to the login page that you specify.
>
> Check out the section of the .NET framework titled "Forms
Authentication
> Provider", located at (watch for line wrap):
>
>

http://msdn.microsoft.com/library/de...onprovider.asp
>
> Hope this helps.
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
> "LL" <li*******@hotmail.com> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > Hi,
> >
> > Where is the best place to check the session's object, if it's null, then
> > redirect the user to login page?
> >
> > put into every page's load event?
> >
> > Thanks.
> >
> >
>
>



Nov 15 '05 #6

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

Similar topics

0
by: Tim T | last post by:
Hi, I have a web application that has a number of users who administer their own data... i have several pages that check to see if a valid userID session exists, and if not, send them to a...
1
by: lydia sista via DotNetMonster.com | last post by:
HI all how dya check if session is null or does not exist? I tried using if Session("cart")= null then ... end if this doesn't work it says 'null' is not declared. 'null' constant is no...
3
by: rony_16 | last post by:
hi , i want to override the object session in class page , because i want to check the Session automaticly in WebForm , without writing "if" in evry page . i know that i need to make a new...
1
by: Kim | last post by:
I would like to check whether the session object contains dataset before retrieving from the data source. If NOT CType( Session("ds"), Dataset) = "" Then dg.DataSource= ds.Tables("dt")...
0
by: tshad | last post by:
I got a piece of code to check if a Web page was refreshed (user pressed refresh button). But I can't get it to work. The code is: ************************************************************...
0
by: kevin bailey | last post by:
I have a framework working where I have multiple pages each checking the authentication status. Unauthorised users are redirected to a login page - otherwise the requested page is shown. ...
9
by: webrod | last post by:
Hi all, how can I check a user/password in a LDAP ? I don't want to connect with this user, I would like to connect to LDAP with a ADMIN_LOG/ADMIN_PWD, then do a query to find the user and...
0
by: seanwalsh | last post by:
Hi I'm new to ASP.NET (from classic ASP) and wasn't aware of the Forms Authentication security when I started working on a website. So I built a login page that stores a CustomUser object in the...
0
by: readnlearn | last post by:
hai, i have written this below code for displaying captcha image whenever i entered incorrect uname,password in login page. for that i disable the controls of captcha like textbox,labels,button and...
0
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...
0
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
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
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,...
1
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...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.