locked
Delete the Session RRS feed

  • Question

  • User-1642741938 posted

    When i click the linkbutton(Logout), the session of a particular person should be deleted and also please tell me where i have to put the code.

    Here is the page code where i have to delete:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Blog : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                Label1.Text = "Welcome: " + Session["UserName"];
            }
            else
            {
                Label1.Visible = false;
                LinkButton1.Visible = false;
            }
        }
    }
    Saturday, October 22, 2011 8:14 AM

Answers

  • User1648350404 posted
    Use Session.Abandon() to clear session and use response.redirect to login page again.

    http://msdn.microsoft.com/en-us/library/ms524310.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 8:17 AM
  • User1413134711 posted

    hi abdur use this one

    Session.Abandon();

    Session.Clear();

    and after that Redirect the page into Login

    Response.Redirect("login.aspx");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 8:19 AM

All replies

  • User1648350404 posted
    Use Session.Abandon() to clear session and use response.redirect to login page again.

    http://msdn.microsoft.com/en-us/library/ms524310.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 8:17 AM
  • User1413134711 posted

    hi abdur use this one

    Session.Abandon();

    Session.Clear();

    and after that Redirect the page into Login

    Response.Redirect("login.aspx");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 8:19 AM
  • User-1642741938 posted

    Why we using the HttpSessionState?

    Saturday, October 22, 2011 8:20 AM
  • User-183374066 posted

    place a logout link button on page

     <asp:LinkButton runat="server" ID="btnLogout" Text="Logout" 
                onclick="btnLogout_Click"></asp:LinkButton>

    and code behind

    protected void btnLogout_Click(object sender, EventArgs e)
            {
                // you can use Abondon method to remove session
                Session.Abandon(); // cancels the current session
                // You can use RemoveAll method to remove sessions
                Session.RemoveAll();
                // You can just remove your desire session
                Session.Remove("UserName");
            }
    Saturday, October 22, 2011 8:21 AM
  • User-1642741938 posted

    Thanks for your replies, i got the solution now.

    Saturday, October 22, 2011 8:22 AM