2012-02-17 17 views
0

私は、セッション状態モードが "InProc"であるasp.net Webアプリケーションを持っています。 Inprocでは、デフォルトでセッションの有効期限は20分です。私は、セッションの有効期限が切れる前に1分間、セッションの有効期限のカウントダウンポップアップを表示したいと思います。しかし、私はどのくらいのミューティングが去ってしまったのか言う財産を見つけることはできません。 19分であるかどうかを知る方法。 は今、私は以下のようにやっている:asp.netのセッションタイマ

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

サーバーのコードが実行される場合には、それがリセットされるので、それは、アイドルタイムアウトです。クライアントでこれを行う必要があります(例: javascript。 http://stackoverflow.com/questions/1470407/get-asp-net-session-last-access-time-or-time-to-timeout – StuartLC

+0

認証チケットを使用する場合、FormsAuthenticationTicket.Expirationプロパティ(DateTime)は次のようになります。有用。 http://msdn.microsoft.com/ja-jp/library/system.aspx.aspx –

答えて

0

あなたはこれを達成するために、いくつかのAJAXを使用することができます。ここ が可能なソリューションです:

<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> 

、あなたがWebメソッドであなたのカウントダウンコードを開発する必要があります。

<%@ 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"; 
} 

} 
関連する問題