By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Check session object?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.