WebサイトでC#を使用して、FormsAuthenticationTicketを使用してセッションを作成しています。
FormsAuthenticationTicketのチケットコードは次のとおりです
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
model.UserName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
admin.Role);
string encTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket) { Expires = ticket.Expiration });
Webサイトのすべての部分がSite.Masterを継承しているので、これらの行の中に何かをSite.Masterに追加したいと思いました。
$(document).ready(function() {
$(window).bind('mousemove mouseclick keydown mousewheel', idle);
});
function idle(e) {
if (window.idleTimeout) {
clearTimeout(window.idleTimeout);
}
<%= FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity; %>
<%= FormsAuthentication.RenewTicketIfOld(identity.Ticket); %>
window.idleTimeout = setTimeout(userIdle, 900000);
}
function userIdle() {
//either do stuff here or trigger the "idle" event
$(window).trigger('idle');
}
これは動作しません。「System.Web.Securityを使用する」ことができないため、FormsIdentityを使用できません。ここ。
キー押下やマウスイベントなどのイベントでチケットを更新し続けるために使用できる同様のロジックはありますか?
参考:ウェブサイトの他の場所に行ってもチケットの有効期限は切れないので、問題ありません。人々がフォームの記入に40分程度を使用し、それを送信しようとしてすべての進行状況を失った場合にのみ。確かにタイムアウトを増やすことはできますが、これは私がやりたいことではありません。