myesn

myEsn2E9

hi
github

SignInManager.SignInAsync 配置登錄過期時間等參數

全局配置,對所有的 SignInXXXAsync 方法生效#

private void ConfigureApplicationCookie(IServiceCollection services)
{
    //// 配置 Identity 登錄 Cookie,比如登錄過期時間等
    //// https://github.com/abpframework/abp/issues/4356#issuecomment-644477874
    //services.ConfigureApplicationCookie(options =>
    //{
    //    //options.AccessDeniedPath = "/Identity/Account/AccessDenied";
    //    //options.Cookie.Name = "YourAppCookieName";
    //    //options.Cookie.HttpOnly = true;
    //    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
    //    //options.LoginPath = "/Identity/Account/Login";
    //    //// ReturnUrlParameter requires 
    //    ////using Microsoft.AspNetCore.Authentication.Cookies;
    //    //options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
    //    //options.SlidingExpiration = true;
    //});
}

在登錄時配置#

await SignInManager.SignInAsync(user, new AuthenticationProperties() 
{
    // 總是記住登錄狀態,因為不記住的話登錄狀態是 session 維持的,瀏覽器關閉後 session 就失效了
    // 比如未勾選時過期時間為1天,勾選之後過期時間為5天
    // 當 IsPersistent = true 時,identity 才會發送 cookie 到客戶端瀏覽器,才能設置過期時間,false 代表使用 session 維持繪畫,在瀏覽器關閉後 se
    IsPersistent = true, //LoginBySmsCodeInput.RememberMe,
    ExpiresUtc = DateTime.Now.AddDays(LoginBySmsCodeInput.RememberMe ? 5 : 1),
});

參考#

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。