Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to secure code for logout when click on logout button.


I was try many code for logout but can't success.
In many codes after click on logout button and press beck button of browser then again go in page.


so please send me secure logout code...



please help me..

Rakesh
Posted
Updated 8-Aug-20 3:37am
Comments
Herman<T>.Instance 7-Apr-12 9:19am    
how do you know some one is logged in? How do you maintain that state?

That is not a problem with the log out code - it is because the Back button is handled within the browser, and does not need a round-trip to the server. Since the page is already loaded, the browser just displays it from it's internal cache and doesn't do a page load at the server.

There isn't a whole lot you can do about it: the best approach is to open your site in a new window that doesn't have a back button. You can get that effect by setting the "toolbar" to "no" when you configure the new window.
 
Share this answer
 
Onclick of logout button, redirect user to logout.aspx page. Add following code in logout.aspx page.

C#
protected void Page_Load(object sender, EventArgs e)
    {
        Session.Abandon();
        
        Response.Redirect(clsCommon.value("login.aspx?mode=logout");
    }
 
Share this answer
 
Comments
BalaMahesh 18-Oct-12 0:51am    
here what is clscommon
Mukund Thakker 18-Oct-12 1:00am    
You can write directly
Response.Redirect("login.aspx?mode=logout");
 
Share this answer
 
Comments
Trak4Net 9-Jul-12 14:27pm    
The cache setting is what will resolve the issue. As stated it is the browser reloading the cached content. Setting the cache expiration or dissallowing the cache will be what you want to do. You do not have to do it in a master page you can do it in a per page situation so if only an admin page is what you want to keep from caching you can set the cache settings for that page.
You can use ASP.NET Login control if you are using Forms authentication that will take care of Logout

http://www.c-sharpcorner.com/uploadfile/raj1979/login-control-in-Asp-Net-3-5/[^]
 
Share this answer
 
Comments
nitesh chaudhary 5-Mar-13 8:29am    
protected void lnkbtnlogout_Click(object sender, EventArgs e)
{
Session.Abandon();
Session.Clear();
Response.Redirect("~/Default.aspx");
}


i am using this code its working but i am pressing backspace ...going to previous page
protected void LogIn_Click(object sender, EventArgs e)
{
Session.Add("uname", txtUname .Text );
Session.Add("pass", txtPass .Text );
DataTable dt = BusinessLayer.GetData("select * from tblLogin where uid='" + txtUname .Text + "' and Upwd='" + txtPass .Text + "'");
if (dt.Rows.Count == 0)
{
//lblmessage.Text = "Invalid username or password";
Response.Write("<script language=javascript>alert('You Are Invalid User')</script>");
Response .Redirect ("Home.aspx");
}
}


C#
protected void lnkbtnlogout_Click(object sender, EventArgs e)
   {
       Session.Abandon();
       Session.Clear();
       Response.Redirect("~/Default.aspx");
   }
 
Share this answer
 
Use a javascript block on top of each page which check the login state every time the page load. This force a login state check too even the user press the [Back] button of the browser.
 
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