Help! implementing user session timeout in winform c#2.0
-
Hello fellas! i'm trying to built an implementation of user session which timeout after a certain pediod. I have a class usersession which does the job. <pre>using System.Timers; public class usersession { private static bool sessionalive; private static Timer usertimer; public static bool SessionAlive { get { return sessionalive; } set { sessionalive = value; } } public static void BeginTimer() { try { SessionAlive = true; //usertimer.Start(); usertimer = new Timer(int.Parse(ConfigurationManager.AppSettings["sessiontime"].ToString())); usertimer.Enabled = true; usertimer.AutoReset = false; usertimer.Elapsed += new ElapsedEventHandler(DisposeSession); } catch (Exception ex) { return; } } private static void DisposeSession(object source, ElapsedEventArgs e) { try { SessionAlive = false; } catch (System.Exception ex) { return; &nbs
-
Hello fellas! i'm trying to built an implementation of user session which timeout after a certain pediod. I have a class usersession which does the job. <pre>using System.Timers; public class usersession { private static bool sessionalive; private static Timer usertimer; public static bool SessionAlive { get { return sessionalive; } set { sessionalive = value; } } public static void BeginTimer() { try { SessionAlive = true; //usertimer.Start(); usertimer = new Timer(int.Parse(ConfigurationManager.AppSettings["sessiontime"].ToString())); usertimer.Enabled = true; usertimer.AutoReset = false; usertimer.Elapsed += new ElapsedEventHandler(DisposeSession); } catch (Exception ex) { return; } } private static void DisposeSession(object source, ElapsedEventArgs e) { try { SessionAlive = false; } catch (System.Exception ex) { return; &nbs
Hi there, Although your idea is not bad, i find it a rather strange way of doing an expired session... what i would do ( although i am no coding god either so feel free to correct me) For example you want your session to be valid for 15 Minutes: You simply make a Session variable like:
session.Item("expirationtime") = DateTime.Now().AddMinutes(15)
then, on every call you make that is < session.Item("expirationtime") , you set this againif(session.item("expirationtime") < DateTime.Now())
{
// redirect the user back to the login page}
Seems a hell of a lot simpler and has better performance then spinning of threads to keep timers ticking.. (500 visitors logged in means 500 threads running a timer)
Do Or Don't, there is no "try catch ex as exception end try"
-
Hi there, Although your idea is not bad, i find it a rather strange way of doing an expired session... what i would do ( although i am no coding god either so feel free to correct me) For example you want your session to be valid for 15 Minutes: You simply make a Session variable like:
session.Item("expirationtime") = DateTime.Now().AddMinutes(15)
then, on every call you make that is < session.Item("expirationtime") , you set this againif(session.item("expirationtime") < DateTime.Now())
{
// redirect the user back to the login page}
Seems a hell of a lot simpler and has better performance then spinning of threads to keep timers ticking.. (500 visitors logged in means 500 threads running a timer)
Do Or Don't, there is no "try catch ex as exception end try"
hello thanks for the reply and sorry for the late response.i didn't check my mail lately and thought(sorry :)) this subject doen't interest anybody.I'm not sure i understand what you are trying to explain but i have a good news.My same codes is working silly enough from me i put the
check.stop();
after calling the loginform.so i did call it before and reset the winforms.forms.timers object on formclosing too.i did some tweak to it.that part was changed toif (!usersession.SessionAlive) { check.Stop(); if(logininstance == null) logininstance = new LoginForm(); logininstance.ShowDialog(); }
thanks a lot! ;)eager to learn