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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Browser back button -> force a logout

Browser back button -> force a logout

Scheduled Pinned Locked Moved ASP.NET
javascripthelpquestion
3 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.
  • G Offline
    G Offline
    gerrybrennan
    wrote on last edited by
    #1

    Hi, I wish to implement the following behaviour: Once logged in to my webapplication if the user hits back button on the browser .... log them out. I am researching a possible solution for this using the "onbeforeunload" Javascript event. However how does do you request a logout initiated from the client side ? Any help would be appreciated

    A P 2 Replies Last reply
    0
    • G gerrybrennan

      Hi, I wish to implement the following behaviour: Once logged in to my webapplication if the user hits back button on the browser .... log them out. I am researching a possible solution for this using the "onbeforeunload" Javascript event. However how does do you request a logout initiated from the client side ? Any help would be appreciated

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Well, But there are few browsers which doesnt places a server call when back button is hit. Even your ajax request in the page will be invoked but with same parameter. I am unsure if it actually can be done. onbeforeunload event is generated when you navigate away from the page, like you close the window, you click on any link etc. By this, you cant trap if back is hit or not...

      gerrybrennan wrote:

      However how does do you request a logout initiated from the client side ?

      Just invoke an AJAX request to the server which will remove the authentication variable in the server.(might be in session) :thumbsup:

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Windows7 API Code Pack
      Simplify Code Using NDepend
      Basics of Bing Search API using .NET

      1 Reply Last reply
      0
      • G gerrybrennan

        Hi, I wish to implement the following behaviour: Once logged in to my webapplication if the user hits back button on the browser .... log them out. I am researching a possible solution for this using the "onbeforeunload" Javascript event. However how does do you request a logout initiated from the client side ? Any help would be appreciated

        P Offline
        P Offline
        PunkIsNotDead
        wrote on last edited by
        #3

        ... or in load event of login.aspx page, just clear the authentication variables! (Session.Remove("Credentials") ? or something like that) :laugh: ...

        And if you want, you can add :^)


        Response.AddHeader("pragma", "no-cache");
        Response.AddHeader("cache-control", "private");
        Response.CacheControl = "no-cache";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();

        on load event to prevent the Back button of browser and let the user see the last page before the log out... good luck! ;P

        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