カスタムの期間、たとえば 1 か月で有効期限が切れる「ユーザー名を記憶する」Cookie を作成しています。HttpOnly = true を追加すると、有効期限がセッションに変更されることに気付きました。どうしてこれなの?なぜこれが起こるのかについてのドキュメントが見つからないようです。
ありがとう。
これがドキュメントです。
Cookie に HttpOnly 属性があり、クライアント側スクリプトからアクセスできない場合は true 。それ以外の場合は false。デフォルトは false です。
基本的には、設定によりサーバーにしか保存されないため、セッション変数になります
次のコードを追加しています。また、タイトルとは異なる動作が得られるようになりました。これをVS2010組み込みサーバーに対してローカルで実行しています。一貫性のない行動を示しているようです。Expires の前後に HttpOnly = true を移動すると、ブラウザーのページを更新するまで動作が変わるように見えました。したがって、すべてが順調で、問題はなかったと思います。さらに、すべての環境で SSL が使用されているわけではないため、HttpOnly フラグと Secure フラグを web.config に移動しています。
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket
(strUserID, //name
false, //IsPersistent
24 * 60); // 24 hours
// Encrypt the ticket.
string encryTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
HttpCookie userCookie = new HttpCookie("Authentication", encryTicket);
userCookie.HttpOnly = true;
Response.Cookies.Add(userCookie);
e.Authenticated = true;
if (LoginPannelMain.RememberMeSet)
{
HttpCookie aCookie = new HttpCookie("email", strUserLogin);
aCookie.HttpOnly = true;
aCookie.Expires = DateTime.Now.AddYears(1);
Response.AppendCookie(aCookie);
}
else
{
HttpCookie aCookie = new HttpCookie("email", "");
aCookie.HttpOnly = true;
Response.AppendCookie(aCookie);
}