Get Session to expire gracefully in ASP.NET

后端 未结 5 1897
南旧
南旧 2020-12-30 11:09

I need a way to tell ASP.NET \"Kill the current session and start over with a brand new one\" before/after a redirect to a page.

Here\'s what I\'m trying to do:

5条回答
  •  囚心锁ツ
    2020-12-30 11:34

    For ASP.NET MVC this is what I'm doing with an action method.

    Note:

    • Returns a simple view with no other resources that might accidentally re-create a session
    • I return the current time and session id so you can verify the action completed succcessfully

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

提交回复
热议问题