まず、キーと値のペアをセッションに追加するログイン ページを作成し、そのページでセッションがそのペアを保持していることを確認しました。次に、セッションでそのペアを探す別のページに移動しようとしましたが、そこにはありません。セッションのタイムアウトを 15000 に設定したので、タイムアウトしません。私は現在、静的クラスを使用してセッション HttpContext.Current.Session を調べています。各ページはこの静的クラスを呼び出してセッションを確認しますが、セッション キー カウント = 0 になるたびに、ログイン ページでペアになった後を除きます。
public static class UserAuthenticationManager
{
public static bool IsAuthenticated()
{
UserAuthenticationTicket ticket = ((UserAuthenticationTicket)HttpContext.Current.Session[DefinesPL.UserTicketSessionName]);
string redirectUrl = String.Format(DefinesPL.LoginPage);
if (ticket != null)
{
if (ticket.IsExpired())
{
HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Redirect(redirectUrl, true);
}
}
else
{
HttpContext.Current.Session.Abandon();
HttpContext.Current.Response.Redirect(redirectUrl, true);
}
return true;
}