ConfigureServices :
services.ConfigureApplicationCookie(
options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = "/AccessDenied";
});
services
.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.Lax;
options.ConsentCookie.Name = ".AspNetCore.ConsentCookie";
});
配置:
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseRouting();
app.UseSession();
当我将[Authorize]
放在任何控制器上时,即使我没有登录,无论页面加载什么,都可以。