Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey I want logout and remove sessions from entire browser. In my code logout button redirects to login page successfully. But when i click back arrow of the browser it directs to pages which i browsed previously. I want to do this..when i click back arrow in the browser it should stay on the login page page and should not give permission to go to other pages using back arrow.

Here my code

Java
private void logoutSession(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        
	    HttpSession  session = request.getSession();
		try{
			String message = "Logout!";	   
	        session.removeAttribute("loggedUser");  
	        session.invalidate();
			request.setAttribute("loginMsg", message);
			response.sendRedirect(request.getContextPath() + "/login2.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}	


How to do this? Thank you in advance!
Posted

put this in Logout button click event...:)


C#
if (Session["sessionName"] != null)
       {

           Session.Clear();//clear session
           Session.Abandon();//Abandon session
           Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
           Response.Cache.SetCacheability(HttpCacheability.NoCache);
           Response.Cache.SetNoStore();
           Response.Redirect("yoururl.aspx")

       }
 
Share this answer
 
Try the following.. which will abandon the session and will not allow to do which is happening to your application...



C#
Session.Abandon();
      Response.Redirect("Login.aspx");



Hope That gona help.
 
Share this answer
 
Here is your answer - Browser back button issue after logout[^].
 
Share this answer
 
Also you can use this
HTML
window.history.forward();
at top of each page.
To learn more http://viralpatel.net/blogs/disable-back-button-browser-javascript/[^]
 
Share this answer
 
Comments
mali_angel 9-Jul-13 0:44am    
thank u all answers :)
Shubhashish_Mandal 9-Jul-13 2:11am    
welcome, and don't forget to mark the question answered

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900