Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made session time setting in web config as
HTML
<sessionState mode="InProc" cookieless="true" timeout="1" />


now i m checking here as..

VB
Protected Overrides Sub OnActionExecuting(filterContext As ActionExecutingContext)
        '*****************************************
        ' check if session is supported
        If HttpContext.Session IsNot Nothing Then
            ' check if a new session id was generated
            If HttpContext.Session.IsNewSession Then

                If Not filterContext.HttpContext.Request.IsAjaxRequest() Then
                    Dim sessionCookie As String = HttpContext.Request.Headers("Cookie")
                    If (sessionCookie IsNot Nothing) AndAlso (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0) Then
                        Dim viewData = filterContext.Controller.ViewData
                        'viewData.Model = username;
                        filterContext.HttpContext.Response.StatusCode = 504
                        'filterContext.Result = new ViewResult { ViewName = "/Home/SessionExpire.aspx", ViewData = viewData };

                        'ctx.Response.Redirect("~/Home/Login");
                        HttpContext.Response.Redirect("~/Case/TimeOut")

                    End If


                End If
            End If
        End If


On
HTML
HttpContext.Response.Redirect("~/Case/TimeOut")


i m calling partial view to call alert , of session end like this

HTML
<script>
         var sessionTimeoutWarning = "You Session is going to finish in one minute.";
         var sessionTimeout = "<%= Session.Timeout %>";
         var timeOnPageLoad = new Date();
         var sessionWarningTimer = null;
         var redirectToWelcomePageTimer = null;
         //For warning
         var sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
         //To redirect to the welcome page
         var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);

         //Session Warning
         function SessionWarning() {
             //minutes left for expiry
             var minutesForExpiry =  (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
             var message = "Your session will expire in another " + minutesForExpiry + " mins. Do you want to extend the session?";

             //Confirm the user if he wants to extend the session
             answer = confirm(message);

             //if yes, extend the session.
             if(answer)
             {
                 var img = new Image(1, 1);
                 img.src = '@Url.Action("CaseManage","Case")';   @*?date=' + escape(new Date());*@

                 //Clear the RedirectToWelcomePage method
                 if (redirectToWelcomePageTimer != null) {
                     clearTimeout(redirectToWelcomePageTimer);
                 }
                 timeOnPageLoad =  new Date();
                 sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
                 //To redirect to the welcome page
                 redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);
             }

             //*************************
             //Even after clicking ok(extending session) or cancel button, if the session time is over. Then exit the session.
             var currentTime = new Date();
             //time for expiry
             var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));

             //Current time is greater than the expiry time
             if(Date.parse(currentTime) > timeForExpiry)
             {
                 alert("Session expired. You will be redirected to welcome page");
                 window.location = "@Url.Action("CaseManage","Case")";
             }
             //**************************
         }

         //Session timeout
         function RedirectToWelcomePage(){
             alert("Session expired. You will be redirected to welcome page");
             window.location = "@Url.Action("Index","LogOn")";
         }

     </script>
.

what does i want, when i got alert, that the, session is going to end, on clicking the, ok button, the, session extends.

Please Help...
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900