編集2
フォーム認証で使用される Cookie は ".ASPXAUTH" と呼ばれ、既定では 30 分後に有効期限が切れるように設定されています。
あなたに行き、要素web.config
を見つけてください。authentication
次のように、Cookie の有効期限 (分単位) を設定できます。
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login"
name="myCookie" <!-- optional, if you want to rename it -->
timeout="2880" /> <!-- expires in 48 hours -->
</authentication>
</system.web>
また
構成に失敗した場合は、次の記事を試してください:リンク
既存の認証チケットをすべてクリアして、カスタム チケットを作成する必要があります。remember me
ユーザーがオプションを選択した場合に実行する必要があるコードは、次のとおりです。
if (rememberMe)
{
// Clear any other tickets that are already in the response
Response.Cookies.Clear();
// Set the new expiry date - to thirty days from now
DateTime expiryDate = DateTime.Now.AddDays(30);
// Create a new forms auth ticket
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, loginModel.UserName, DateTime.Now, expiryDate, true, String.Empty);
// Encrypt the ticket
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
// Create a new authentication cookie - and set its expiration date
HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
authenticationCookie.Expires = ticket.Expiration;
// Add the cookie to the response.
Response.Cookies.Add(authenticationCookie);
}