services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login/"; options.AccessDeniedPath = "/Account/Forbidden/"; });
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7) });
示例代码:
[Authorize] public IActionResult SecureAction() { return View(); }
示例代码:
services.Configure
如果以上方法仍无法解决问题,请检查应用程序的其他设置和代码。