Avoid mulitple login for same user
-
Hello I am developing on web-application in asp.net using c#. In that I want to avoid mulitple login for same user. That means one user can login only at a time. So I want without Database hitting. I tried this by taking Application varible,if user properly make sign out then it is working. But when user closes brower in another way,then my coding is not working. I want to it using Application varible or Session or any method but without hitting the database. Bye Swapnil Bhavsar
-
Hello I am developing on web-application in asp.net using c#. In that I want to avoid mulitple login for same user. That means one user can login only at a time. So I want without Database hitting. I tried this by taking Application varible,if user properly make sign out then it is working. But when user closes brower in another way,then my coding is not working. I want to it using Application varible or Session or any method but without hitting the database. Bye Swapnil Bhavsar
You may want to use the application cache with a sliding expiration window so if the user closes the browser without logging out the cached variable will expire after X number of minutes. If you can be confident that popups are allowed, you can perform a window.open to a page designed to clear the cached flag on the window.close event, thus forcing the variable to clear even if the user simply closes the browser without logging out, but this is really only a viable solution if you have a higher degree of control over the user's environment. Jim Conigliaro jconigliaro@ieee.org
-
You may want to use the application cache with a sliding expiration window so if the user closes the browser without logging out the cached variable will expire after X number of minutes. If you can be confident that popups are allowed, you can perform a window.open to a page designed to clear the cached flag on the window.close event, thus forcing the variable to clear even if the user simply closes the browser without logging out, but this is really only a viable solution if you have a higher degree of control over the user's environment. Jim Conigliaro jconigliaro@ieee.org
-
Sir, Can you please send the code to avoid the multiple log in of the same user without database. Thanks and Regards Amaneet Brar
You can try using functions like these in a static helper class:
/// /// Determines if the user is currently logged in /// /// The login name of the user to check /// True of the user is currently logged into the application, false otherwise internal static bool IsUserLoggedIn(string userName) { return (HttpContext.Current.Cache["userName"] != null); } /// /// Sets up the cache settings to track if the user is logged in or not /// /// The login name of the user internal static void SetLoginState(string userName) { HttpContext.Current.Cache.Add(userName, true, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), CacheItemPriority.Normal, null); } /// /// Resets the sliding expiration of the login state by resetting the value /// /// The name of the user to set internal static void TickleLoginState(string userName) { if (HttpContext.Current.Cache[userName] == null) SetLoginState(userName); else HttpContext.Current.Cache[userName] = true; } /// /// Removes the user's key from the login state /// /// The login name of the user internal static void ClearLoginState(string userName) { HttpContext.Current.Cache.Remove(userName); }
Jim Conigliaro jconigliaro@ieee.org