locked
Session timeout - redirection di Login page RRS feed

  • Question

  • User-1546622187 posted

    Hi, I'm implementing a Web Application using ASP.NET MVC and for views I'm using Razor view.

    My Web Application contains some page, for example a Login page (which is the initial page). To manage the session, I've created a SessionManagement class which is used in my controller.

    One week ago i've started my Web Application and I didn't do anything for many time (because I was far away from my workstation); when I  returned to my workstation, I've tried to navigate in my Web Application, but an error occurs; it was as if all the variables had been "cleaned up".

    So I want something like that: if the user doesn't use the Web App for 30 minutes, it is redirect to the Login page

    How I can do that? 

    Tuesday, October 29, 2019 10:31 AM

Answers

  • User-1546622187 posted

    If someone is interested, I've solved this problem in the following way:

    I've added those lines to every action in my controller:

    if (TempData["SessionData"] == null)
        return RedirectToAction("GeneralError");

    and GeneralError action contains:

    SessionManagementModel session = new SessionManagementModel();
    session.LoginError = "SESSION EXPIRED!";
    session.Flag1 = 0;
    session.Flag2 = 0;
    [...]
    TempData["sessionData"] = session;
    return RedirectToAction("IndexRedirect");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 29, 2019 11:40 AM