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. Logout from MVC

Logout from MVC

Scheduled Pinned Locked Moved ASP.NET
asp-netarchitecturehelp
5 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.
  • P Offline
    P Offline
    Pankaj Saha
    wrote on last edited by
    #1

    Hi, I have a MVC application and I have to logout. To logout from the application I have created a link on te master page

    [ <a id="A2" name="lnkLogout" href="http://localhost:1234/Home/LogOut" >Logout</a> ]

    and created the LoutOut action in the controller page

    public ActionResult LogOut()
    {
    Session.Clear();
    Session.Abandon();
    Redirect("http://AnotherApplicaton/Home/LogOut");
    }

    Now when I click on the LogOut link its redirect to the LogOut action and in the LogOut action its delete all the session, but when I click on the back button of the browser its get back to the previous page and sessions are still alive. Does anyone have the solution of this problem.

    Pankaj

    G A 2 Replies Last reply
    0
    • P Pankaj Saha

      Hi, I have a MVC application and I have to logout. To logout from the application I have created a link on te master page

      [ <a id="A2" name="lnkLogout" href="http://localhost:1234/Home/LogOut" >Logout</a> ]

      and created the LoutOut action in the controller page

      public ActionResult LogOut()
      {
      Session.Clear();
      Session.Abandon();
      Redirect("http://AnotherApplicaton/Home/LogOut");
      }

      Now when I click on the LogOut link its redirect to the LogOut action and in the LogOut action its delete all the session, but when I click on the back button of the browser its get back to the previous page and sessions are still alive. Does anyone have the solution of this problem.

      Pankaj

      G Offline
      G Offline
      geeeeeeeetha
      wrote on last edited by
      #2

      hi <script type="text/javascript" language="javascript"> javascript: window.history.forward(1); </script>

      1 Reply Last reply
      0
      • P Pankaj Saha

        Hi, I have a MVC application and I have to logout. To logout from the application I have created a link on te master page

        [ <a id="A2" name="lnkLogout" href="http://localhost:1234/Home/LogOut" >Logout</a> ]

        and created the LoutOut action in the controller page

        public ActionResult LogOut()
        {
        Session.Clear();
        Session.Abandon();
        Redirect("http://AnotherApplicaton/Home/LogOut");
        }

        Now when I click on the LogOut link its redirect to the LogOut action and in the LogOut action its delete all the session, but when I click on the back button of the browser its get back to the previous page and sessions are still alive. Does anyone have the solution of this problem.

        Pankaj

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

        No need to think about the browser back button... If there is no session, every request that is made from the client in the cached page will generate errors. :) Also if possible place history.go(1); in the masterpage or every page. So that whenever the back button is clicked, it will automatically forward to the latest page. ;)

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


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        P 1 Reply Last reply
        0
        • A Abhishek Sur

          No need to think about the browser back button... If there is no session, every request that is made from the client in the cached page will generate errors. :) Also if possible place history.go(1); in the masterpage or every page. So that whenever the back button is clicked, it will automatically forward to the latest page. ;)

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


          My Latest Articles-->** Simplify Code Using NDepend
          Basics of Bing Search API using .NET
          Microsoft Bing MAP using Javascript

          P Offline
          P Offline
          Pankaj Saha
          wrote on last edited by
          #4

          Thanks for you replay. Back button is not my problem. The problem is sessions are not expiring. When I go back to previous page and refresh the browser, I get all the information from the database again, this should not happen. Because before every database request its checks whether session is exist or not. If session is not exists then no database call will be fired. But this is not happening after the logout.

          Pankaj

          A 1 Reply Last reply
          0
          • P Pankaj Saha

            Thanks for you replay. Back button is not my problem. The problem is sessions are not expiring. When I go back to previous page and refresh the browser, I get all the information from the database again, this should not happen. Because before every database request its checks whether session is exist or not. If session is not exists then no database call will be fired. But this is not happening after the logout.

            Pankaj

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

            I think it is better to check a Session value on every call to the server. Like :

            try{
            if(Convert.ToBoolean(Session["IsAuthenticated"]) != true)
            Server.Transfer("loginpage.aspx");
            }
            catch{
            Server.Transfer("loginpage.aspx");
            }

            During Login put this Session Value and In Logout clear out this value. :)

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


            My Latest Articles-->** Simplify Code Using NDepend
            Basics of Bing Search API using .NET
            Microsoft Bing MAP using Javascript

            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