Haneef Puttur

MVC C# Session Time Out Popup

Challenge :

Develop an application which will alert the user the session is going to timeout in 30 seconds and allow the user to extend the session. If there is no activity session will be logged off.

Features:

 

Step 1 :

Create a partial view  _KeepAlive.cshtml inside Views/Shared folder and copy the following code.

https://github.com/haneefputtur/Protect_Timeout/blob/master/_KeepAlive.cshtml

Please edit these lines to match your configuration.

var sessoff = "/Account/Logoff"; //edit with your logoff url
var sessurl = "/home/KeepSessionAlive"; // edit line with your KeepSessionAlive URL of step 2

Step 2 :

Create an Action Method inside the controller and name it as KeepSessionAlive() and copy following code

[HttpPost]
public JsonResult KeepSessionAlive() {

return new JsonResult
{
Data = "Beat Generated"
};
}

Step 3:

 

add time out values in web config inside system.web.

 <sessionState timeout="4"></sessionState>

Step 4 :

Include the partial view inside Layout.cshtml

    @if (Request.IsAuthenticated)
    {
        @Html.Partial("~/Views/Shared/_KeepAlive.cshtml")
    }

 

 

Exit mobile version