(ユーザー名 textBox - パスワード textBox ) と [Remember Me CheckBox] オプションを持つ asp.net ログイン Web フォームがあります。ユーザー ログイン時に以下のコードを実行します。
if (provider.ValidateUser(username, password))
{
int timeOut = 0x13;
DateTime expireDate = DateTime.Now.AddMinutes(19.0);
if (rememberMeCheckBox.Checked)
{
timeOut = 0x80520;
expireDate = DateTime.Now.AddYears(1);
}
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(username, true, timeOut);
string cookieValue = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieValue);
cookie.Expires = expireDate;
HttpContext.Current.Response.Cookies.Add(cookie);
AddForLogin(username);
Response.Redirect("...");
}
ユーザーが認証された後のコードのように、メソッドを呼び出してdbにログインしたことを記録しますAddForLogin(username);
しかし、ユーザーがログイン時に私を記憶することを選択した場合、Cookieを使用するため、このログインメソッドが実行されないときはいつでもサイトにアクセスしようとします...だから私は多くの質問があります:
1-これはログイン操作をログに記録するための最良の方法ですか、それとも他に良い方法はありますか?
2-私の場合、ユーザーが選択したことを覚えている場合にログイン操作をログに記録する方法は?