Last post Sep 14, 2012 01:17 AM by jprochazka
Sep 14, 2012 12:38 AM|arun arun|LINK
In my project I want to write logout code which will work on any browser . My problem is when I login into my home page I am creating session . So in each and every page i am going to check weather session count is there (Session.Count>0)
if session count is not there means i am redirecting to login screen and in Logout click i am clearing All Session (Session.Abandon()) . Is this proper way to follow what I have done .
If any suggestions are there means please suggest me .
Thanks in advance
Sep 14, 2012 12:58 AM|Prince Srivastava|LINK
are you store other value rather than login detail . if yes then do not use count becuase if you use two or three session value and in
one you store login value then it counts always greator than one . rather than you login or not .
for this like
in login page you store the session value like below
after successful login
and check in page if
if(Session["loginD"] != null)
hope this will help you...
Sep 14, 2012 01:17 AM|jprochazka|LINK
Calling Abandon() should do the trick.
You can also call Session.Clear().
Do this on page_Load of the logout page.
On pages your protecting you can check if a session variable you set when they logged in is set to what it should be while they are logged in by using code like so. Keep in mind "SomeSessionVariableYouSet" is the session variable you are looking for to insure they are logged in so change this to that variable.
if (Session["SomeSessionVariableYouSet"] == null)
// Session variable does not exist so send then to the login page.
// The person is logged in so the rest of the code from here on out runs.
Also the type browser being used does not matter when using sessions. A session is stored server side and can be handled by your code no matter the browser being used in this way.
Session.Clear() removes all values from the session.
Session.Abandon() destroys the session.