Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Avoid mulitple login for same user

Avoid mulitple login for same user

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabase
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swapnilbhavsar
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • S swapnilbhavsar

      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

      J Offline
      J Offline
      Jim Conigliaro
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • J Jim Conigliaro

        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

        A Offline
        A Offline
        amaneet
        wrote on last edited by
        #3

        Sir, Can you please send the code to avoid the multiple log in of the same user without database. Thanks and Regards Amaneet Brar

        J 1 Reply Last reply
        0
        • A amaneet

          Sir, Can you please send the code to avoid the multiple log in of the same user without database. Thanks and Regards Amaneet Brar

          J Offline
          J Offline
          Jim Conigliaro
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups