簡體   English   中英

LoginPath不重定向(asp.net核心)

[英]LoginPath does not redirect (asp.net core)

在configure上的startup.cs上,我有:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies",
    LoginPath = new PathString("/Account/Login/"),
    AccessDeniedPath = new PathString("/Account/Forbidden/"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});

在普通控制器上:

[Authorize]
public class HomeController : Controller
{
    public IActionResult Index() { return View();  }
}

在AccountController上:

public class AccountController : Controller
{
    [AllowAnonymous]
    public IActionResult Login() { return View(); }
}

未經授權訪問“主頁/索引”應重定向到登錄名,但返回空白頁。 我在提琴手上收到401,但頁面未重定向。 似乎沒有什么錯,但仍然無法正常工作。 有人知道為什么嗎?

您遇到的AutomaticChallenge選項問題。 此選項導致IISIntegration與Cookie中間件之間發生沖突,請參見此處的詳細說明。

如果使用[Authorize],解決方案是將以下代碼添加到ConfigureServices(IServiceCollection services) startup.cs中

services.AddAuthorization(options =>
{
    options.DefaultPolicy = new AuthorizationPolicyBuilder("Cookies").RequireAuthenticatedUser().Build();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM