Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am loging out using the following code on click event of logout button:

MIDL
FormsAuthentication.SignOut();
Session.Abandon();
Response.Redirect("Home.aspx");


Page gets load when i click on back button or paste the previous url in address bar After logout.

How prevent this without disable the back button.
Posted
Comments
Abdul Quader Mamun 15-Dec-10 6:49am    
Use a session variable and set session null when logout and check every page load event. If it is null then back to home page.
Aman4.net 15-Dec-10 7:14am    
Dear Abdul,

I am doing this on page load and checking the session on preinit to load masterpage.. But problem still stands

Chances are that when you click the back button the page is coming from cache.

If that is so, you need to disable page output cache on that page. You can try out these:

In aspx Markup

<%@ OutputCache Duration="0" VaryByParam="none" %>


Or, in CodeBehind

Response.Cache.SetCacheability(HttpCacheability.NoCache);
 
Share this answer
 
Comments
Aman4.net 15-Dec-10 23:37pm    
its generating error i.e. the duration attribute must be positive if i make it 1 then it does not working...
This Trip/Trick will clear everything...Fine one.

Browser back button issue after logout[^]
 
Share this answer
 
Comments
Aman4.net 15-Dec-10 23:46pm    
Thanx its working fine but while i paste the previous url in address bar again i get the last page..
Try this link here, basically adding some cache directives

http://www.extremeexperts.com/Net/FAQ/DisablingBackButton.aspx[^]
 
Share this answer
 
Thanks to all of you for posting comment and answer..

Here i m going to implement java script to close window after logout it will close the window without any confirmation. "Without any confirmation" becoz i don't want that user click on no and get the same page again.

The code is following:

XML
Response.Write("<script language='javascript'>");
        Response.Write("{");
        Response.Write("window.open('','_self','');");
        Response.Write("window.close();");
        Response.Write("}");
        Response.Write("</script>");
 
Share this answer
 
Comments
Aman4.net 16-Dec-10 0:33am    
but its temporary coz if i will change the password and logout at that time i cann't close window..
Use this code onclick of logout button
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("Logout.aspx");

Hope this will solve your problem.
 
Share this answer
 
v2
Comments
Aman4.net 16-Dec-10 0:29am    
Sorry Not effective
Toniyo Jackson 16-Dec-10 1:15am    
Always write your code inside code block. Not in inline code.

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