2

私が作成している単純な ASP.NET MVC SPA アプリケーションでいくつかのサード パーティのログイン プロバイダーを使用するために、このチュートリアルに従いました。構成は十分に単純で (私は実際に Twitter と Microsoft を有効にしました)、サインイン プロセスは正しく機能しますが、ユーザー資格情報はブラウザー セッション Cookie にのみ保存され、ブラウザー セッション間で保持されません。

また、NuGet のalpha-1 サンプル プロジェクトを使用してみましたが(同じ基本構成が適用されています)、これも機能しません (少なくとも私の環境では)。

Web アプリケーションはローカルでのみホストされます (テストする Azure アカウントがないため)。

設定が影響すると思いましたExpireTimeSpanが、そうではありません:

 // Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(GetCookieAuthenticationOptions());


private static CookieAuthenticationOptions GetCookieAuthenticationOptions()
{
    var options = new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        CookieSecure = CookieSecureOption.SameAsRequest,
        SlidingExpiration = true,
        CookieName = "MYSECURITY",
        ExpireTimeSpan = TimeSpan.FromDays(45.0),
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider
        {
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(20),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
        }
    };

    return options;
}

Cookie (コードが実行されていることを検証するために、Cookie のデフォルト名を意図的に変更しました。デフォルトでは動作しません):

セッション有効期限のある Cookie

4

1 に答える 1