Click here to Skip to main content
11,630,646 members (78,649 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 7-Apr-12 3:11am
Comments
digimanus at 7-Apr-12 9:19am
   
how do you know some one is logged in? How do you maintain that state?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Onclick of logout button, redirect user to logout.aspx page. Add following code in logout.aspx page.

protected void Page_Load(object sender, EventArgs e)
    {
        Session.Abandon();
        
        Response.Redirect(clsCommon.value("login.aspx?mode=logout");
    }
  Permalink  
Comments
BalaMahesh at 18-Oct-12 0:51am
   
here what is clscommon
Mukund Thakker at 18-Oct-12 1:00am
   
You can write directly
Response.Redirect("login.aspx?mode=logout");
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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");
}
}


protected void lnkbtnlogout_Click(object sender, EventArgs e)
   {
       Session.Abandon();
       Session.Clear();
       Response.Redirect("~/Default.aspx");
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
Comments
Trak4Net at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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/[^]
  Permalink  
Comments
nitesh chaudhary at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

protected void btnlogout_Click(object sender, EventArgs e)
{
Session.Clear();
Session.RemoveAll();
Session.Abandon();
 
      System.Web.Security.FormsAuthentication.SignOut();
       Response.Redirect("home1.aspx");
 
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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.
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web01 | 2.8.150723.1 | Last Updated 25 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100