アプリでカスタム エンティティを使用してフォーム認証を使用しています。
私が経験している問題は、認証されたセッションが予想される 10 分よりも早く期限切れになることです。
その Cookie に対して認証された要求が来るたびに、Cookie を更新する必要があると思いますか?
セッションを維持するために正しいことはありますか?
ありがとう - 従うべきコード:
Web.Config
<authentication mode="Forms">
<forms loginUrl="/Admin/Account/LogOn" slidingExpiration="true" />
</authentication>
サインイン時
var identity = new AppIdentity(member.Fullname, member.Id, roles.ToArray());
FormsAuthentication.SetAuthCookie(identity.ToString(), false);
var myCookie = FormsAuthentication.GetAuthCookie(identity.ToString(), false);
myCookie.Domain = string.Format(".{0}", "mydomain.com");
HttpContext.Current.Response.AppendCookie(myCookie);
Global.cs
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
var ticket = TryDecryptCookie(cookie);
if (ticket == null)
{
return;
}
var identity = new AppIdentity(ticket);
var principal = new GenericPrincipal(identity, identity.Roles);
Context.User = principal;
}