1

Asp.Net でスライド有効期限 Cookie を構成しようとしています。認証後 5 分で有効期限が切れる Cookie が Google Chrome 開発者ツールの Cookie マネージャーに表示されることを期待していますが、「セッション」として表示され、サインアウト ボタンがクリックされるまで有効期限が切れることはありません。ブラウザを閉じると消えます。

Cookie は常にセッション Cookie として設定されます

以下は現在のコードです。この Web サイトでは、nuget パッケージを使用した Saml ベースのシングル サインオン認証を使用してKentor.AuthServicesいます (現在は として知られていSustainSys.Saml2ますが、バージョンが遅れています)。

app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/signin"),
    CookieSecure = CookieSecureOption.SameAsRequest,
    ExpireTimeSpan = TimeSpan.FromMinutes(5),
    SlidingExpiration = true,
    Provider = new CookieAuthenticationProvider
    {
        OnApplyRedirect = ctx => { },
        OnResponseSignIn = context =>
        {
            context.Properties.AllowRefresh = true;
            context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5);
        }
    }
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

Kentor.AuthServices.Configuration.Options.GlobalEnableSha256XmlSignatures();

ブロックは、このOnResponseSignInMSDN の回答に基づいて最近追加されました: https://forums.asp.net/t/2121970.aspx?OWIN+Authentication+ExpireTimeSpan+not+working

30 分間の非アクティブ期間で Cookie の有効期限が切れるようにします。上記のコードは、テストを容易にするために 5 に設定されています。

4

1 に答える 1