登录后的ASP.NET MVC Core 3.0在浏览器后退按钮上再次显示登录页面,单击

问题描述 投票:0回答:1

一旦用户登录并按返回按钮,则用户需要再次登录。我想解决这个问题。谁能对此有所了解?

Error Screen

//startup.cs
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options=>
{
     options.Cookie.Name = "Dementia.Cookie";
     //options.EventsType = typeof(Infrastructure.Persistance.GenericUser);
     options.LoginPath = "/Home/Login";
     options.LogoutPath = "/Home/Logout";
     options.ExpireTimeSpan = TimeSpan.FromMinutes(5); //TimeSpan.FromDays(1);
     options.SlidingExpiration = false;             
});

 //Controller
 [Authorize]
 [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
 public IActionResult Dashboard()
 {
      return View();
 }
asp.net-core-2.0 asp.net-core-3.0 .net-core-3.0
1个回答
0
投票

我已手动将其存储在cookie仪表板的url中,并验证了其身份正常。

 var claims = new[] {
                        new Claim(ClaimTypes.Name, userInfo.Name),
                        new Claim(ClaimTypes.Role, userInfo.Category),
                        new Claim(ClaimTypes.Uri, "/Home/Dashboard"),
                        new Claim("UserId", userInfo.UserId),
                        new Claim("Id", userInfo.Id)};

public IActionResult Login()
    {
        if (HttpContext.User.Identity.IsAuthenticated)
        {
            return Redirect(HttpContext.User.FindFirst(ClaimTypes.Uri).Value);
        }
        return View();
    }
© www.soinside.com 2019 - 2024. All rights reserved.