最近、私は.netコア2.0で私の新しいウェブサイトを作成しました。認証に永続的なクッキーを使用しています。私はまた、言語のための永続的な文化のクッキーを使用しています。.netコア2.0の永続認証クッキー
私のウェブサイトは空白共有プールでホストされており、マシンキーは指定していません。
問題。 非アクティブ(新しいブラウザ)の数時間後に私のウェブサイトを再オープンすると、私は認証クッキーを失ってしまい、再度ログインする必要がありますが、最後のセッションごとにカルチャークッキーが機能します。
私もセットアップアプリケーションの洞察力は私のアプリケーションを温めておく(2ヶ所から10分ごとにウェブサイトをpingする)。
LoginController
if (this.accountService.ValidateOTP(phoneNumber, otp))
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.MobilePhone, phoneNumber),
new Claim(ClaimTypes.Name, phoneNumber)
};
var userIdentity = new ClaimsIdentity("Custom");
userIdentity.AddClaims(claims);
ClaimsPrincipal userPrincipal = new ClaimsPrincipal(userIdentity);
//await HttpContext.SignOutAsync("AnimalHubInstance");
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
userPrincipal,
new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = DateTime.Now.AddYears(1),
});
}
スタートアップ
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(option =>
{
option.LoginPath = new PathString("/Account/Unauthorized");
option.LogoutPath = new PathString("/Account/Logout");
option.Cookie.Name = ".myAuth";
option.ExpireTimeSpan = TimeSpan.FromDays(365);
option.Cookie.Expiration = TimeSpan.FromDays(365);
});
私はauthとculture cookieがlocalhostに使用されていることに気付きました。この問題は、アプリケーションがAzure Webアプリケーションにデプロイされている場合にのみ発生しますか?また、[データ保護を構成する](https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview)またはプライシング層を基本またはそれ以上に拡大してこれを絞り込むこともできます問題。さらに**常にオン**機能を有効にすると、アプリを常に読み込み状態に保つことができます。また、ウェブアプリは、基本モードまたは標準モード、[ここ](https://docs.microsoft.com)に従う必要があります。/en-us/azure/app-service/web-sites-configureを参照)。 –
@BruceChen現在のところ、私は基本以上には行くことができません。私はこの問題がAzureにしかないと考えています(今私は新しいインスタンスを作成して詳細を掘り下げています)。私は、アプリケーションの洞察力を設定して、自分のサイトを警告し続けることができます。再起動後、私のアプリケーションはまだ動作しています(ログインして文化を維持する) –