0

I have an asp.net web application where the sessionstate mode is "InProc". For Inproc, by default the session expiry is 20minutes. I would like to display a session expiry countdown popup for one minute before the session expires. But i cant find a property that says how many mimutes has goneby. How to know if it is the 19th minute. Right now i am doing like below:

if (Context.Session != null)// Check whether the session is null
             { 
              if (Session.IsNewSession)// If the session is null, check whether the session is new
               {
               Response.Redirect("../SessionTimeout.aspx");//Redirect to time out page
               }
             }
2
  • 2
    It's an idle timeout, so it is reset if your server code executes. You need to do this on the client, e.g. javascript. stackoverflow.com/questions/1470407/… Commented Feb 17, 2012 at 7:31
  • If you use the authentication ticket, the FormsAuthenticationTicket.Expiration Property (DateTime) is useful. See msdn.microsoft.com/en-us/library/…. Commented Feb 17, 2012 at 7:55

1 Answer 1

0

you can use some ajax to accomplish this. here is a possible solution:

<script type="text/javascript">

    function checkAuthenticated() {
        {
            $.ajax({
                type: "POST",
                url: "CheckAutheticated.asmx/checkAuthenticated",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: checkAuthenticatedOk,
                error: checkAuthenticatedError
            });
        }
    }
    function checkAuthenticatedOk() { }
    function checkAuthenticatedError() {
        $("#sessionExpiredCover").show();
    }
    </script>
    <style type="text/css">
    #sessionExpiredCover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100000;
    display: none;
    background-color: #fff;
    /*opacity: .7;
    filter:progid:DXImageTransform.Microsoft.BasicImage(opacity=.7);*/
    }
    </style>

<div id="sessionExpiredCover">
    <div style="background-color:#fff; margin:100px; height:200px; width:400px;"><h1>Session expired</h1>
        <br />
        <asp:HyperLink NavigateUrl="~/Login.aspx" runat="server" Text="Please log in again" />
    </div>
</div>

then you have to develop your countdown code in the WebMethod:

<%@ WebService Language="C#" Class="CheckAutheticated" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment     the following line. 
[System.Web.Script.Services.ScriptService]
public class CheckAutheticated  : System.Web.Services.WebService {

[WebMethod]
public string checkAuthenticated()
{
   //your countDownCode 
   return "authenticated";
}

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.