Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i logout from asp.net page but it still login ,if i copy link in new tab after logout it still login , also after logout if i press back button of browser it still show login,
i need help. i add the code of logout page also plz help

What I have tried:

public partial class logout : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                Session.Clear();


                Session.Abandon();
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                FormsAuthentication.SignOut();
                Session.Remove("LOGINNAME");
                Session.Remove("LOGINPASSWORD");
                Session.Remove("Index");
                Session.Remove("Default");
                Session.Remove("logout");
                Session.Contents.RemoveAll();
                Session.RemoveAll();
                Cache.Remove("LOGINNAME");
                Cache.Remove("LOGINPASSWORD");
                Cache.Remove("AGENTID");

                Response.Cache.SetNoStore();
                Response.Cache.SetNoServerCaching();

                Response.Expires = -1;
                Session.Timeout=1;
                Response.Redirect("Default.aspx", true);
                Response.Flush();
                

            }
        }
Posted
Updated 16-Aug-17 20:50pm
Comments
Richard Deeming 17-Aug-17 10:18am    
Session.Remove("LOGINNAME");
Session.Remove("LOGINPASSWORD");

You're using Forms authentication, so there's no need to store the username anywhere else. And you should NEVER store the password in memory, or in a cookie.

That also makes me suspect that you might be storing the password in the database in plain text, which is a serious security failure.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

Cache.Remove("LOGINNAME");
Cache.Remove("LOGINPASSWORD");
Cache.Remove("AGENTID");

The Cache is global to your application, not to a specific user. If you're storing user-specific details in the Cache, then you're in for some serious bugs once multiple users are using your application at the same time!

1 solution

One problem could be the :
C#
Response.Redirect("Default.aspx", true);

since when you give the value true to the Response.Redirect
nothing bellow that specific line of code will be executed....
In order to execute the
C#
Response.Flush
you have to
assign the value false in order to also check for any lines of code beneath
the Response.Redirect.

You could also try to use
C#
Response.End

instead of Response.Flush...
This way the
C#
EndRequest
will be triggered..
 
Share this answer
 
Comments
Ahsan Aijaz 17-Aug-17 5:48am    
Buddy Not Work......
Any buddy Help Me.
Richard Deeming 17-Aug-17 10:14am    
If it doesn't work, why have you accepted the solution?

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