You must Sign In to post a response.
  • Category: ASP.NET

    How to expire the session in asp.net

    hi ,
    please tell me how to expire the session in asp.net ...
  • #586286
    session.abandon() should be used to expire the session.
    Regards,
    Programmer

    http://www.dotnetutorial.com/interview-questions.aspx?catid=1

  • #586287
    public ActionResult ExpireSession()
    {
    string sessionId = Session.SessionID;
    Session.Abandon();
    return new ContentResult()
    {
    Content = "Session '" + sessionId + "' abandoned at " + DateTime.Now
    };
    }

  • #586289
    hi programmer,

    i used this but when i click on the back button it returns the page and session not expire on that page ..

    Ajay Kumar

  • #586291
    hi try this

    session.abondon();
    Response.redirect("LoginPage",false);




    Thanks and Regards

  • #586319
    use this code for session expire

    Session.Abandon();


    hope this will help you

  • #586321
    hi.....

    Session.RemoveAll();
    Session.Abandon();
    Session.Clear();
    Response.Cache.SetNoTransforms();
    Response.Clear();
    Response.Cache.SetExpires(DateTime.Now);
    Response.Cookies.Clear();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Redirect("Login.aspx");

    I think it will work you...

    Regards,
    Divyashree.k
    Experience is the name every one gives to their mistakes.

  • #586502
    Hi,
    You can use the Session.Abandon() to end the active session.

    Session.Abandon()

    All is well.
    Thanks,
    Dharma
    Editor,Mentor,MVM
    Try and fail but don't fail and try


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.