Click here to Skip to main content
15,916,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I had a problem with logout i.e., if a user logout then it automatically clears the session and returning back to login but when i press browser back then it displayed the previous page and automatically returning to login page. That way i don't require.

What I have tried:

Session.Clear();
Session.Abandon();
Session.RemoveAll();
FormsAuthentication.SignOut();
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Redirect("~/Login.aspx", false);


This code is written in logout.aspx page Page_Load Event.

What is require is after logout if i press logout also the previous page should not be visited and back to login only i required to stay in the same page i.e., login.aspx. Can it be achieved or not anyone can explain me if i am thinking in a wrong way.
Posted
Updated 7-Jan-19 19:22pm
v2
Comments
F-ES Sitecore 1-Oct-18 5:21am    
Does it matter that someone can view something they've already viewed? This happens when the page is retrieved from the cache rather than a new request being made. To stop this happening you'd need to disable caching on your site, but that will negatively affect performance just to stop someone seeing something they've already seen.
Member 8583441 1-Oct-18 5:24am    
"To stop this happening you'd need to disable caching on your site"

to achieve this how can i do sir.
F-ES Sitecore 1-Oct-18 5:26am    
Google "asp.net disable cache" and you'll find lots of examples

https://forums.asp.net/t/1060173.aspx?How+to+disable+cache
Member 8583441 1-Oct-18 5:31am    
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">

I used these two lines but no use. These two lines i kept at layout page at exactly down the line of head tag i.e,

<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
But no use sir
Member 8583441 1-Oct-18 5:37am    
I want in this way sir
https://www.aspsnippets.com/Articles/Disable-Browser-Back-Button-after-LogOut-in-ASPNet-using-JavaScript.aspx

1 solution

write this in your server side page_load event
if (Session.Count != 0)
{

}
else
{
Response.Redirect("loginpage.aspx");
}
 
Share this answer
 

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