#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    9
    Rep Power
    0

    Simple Logout in C#


    I need to do a simple logout using session in c#.
    I am suppose to disable the Back button in Windows Explorer
    everytime I finish logging in. How do I go about doing that?
    The logout codes are as such. Thank you.

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    [code]
    namespace NokiaCert
    {
    /// <summary>
    /// Summary description for logout.
    /// </summary>
    public class canLogout : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here

    //Session.Remove("userRoles");
    Session.Remove("userName");
    Session.Abandon();
    Response.Redirect("canMain.aspx");
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion
    }
    }
    [code]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    Germany
    Posts
    166
    Rep Power
    10
    In fact, you should add a method to the page leading to the logout page which checks if the session still exists. If the session doesn't exist anymore (cause the user logged out) redirect him via response.redirect() to your login page.

IMN logo majestic logo threadwatch logo seochat tools logo