5
我想在一个Asp.net核心应用程序(dnx 4.5)中使用cookie身份验证。请注意,因为我具有自定义身份验证机制(radius),所以我没有使用核心身份验证提供的开箱即用机制。当用户未通过身份验证时,我想重定向到登录页面。Asp.net核心授权重定向不发生
我在Startup.cs中添加了以下代码。我们的想法是,当用户没有通过验证被重定向到登录控制器:
app.UseCookieAuthentication(options => { options.LoginPath = new Microsoft.AspNet.Http.PathString("/Login"); });
在我的家乡控制器我有:
[Authorize]
public IActionResult Index()
{
return View();
}
在我登录控制器我返回对应的视图半径登录形式:
[AllowAnonymous]
public IActionResult Index()
{
return View();
}
但是,当我运行应用程序时,重定向从不发生。看看控制台输出我看到以下内容:
warn: Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker[0]
Authorization failed for the request at filter 'Microsoft.AspNet.Mvc.Filters.AuthorizeFilter'.
info: Microsoft.AspNet.Mvc.ChallengeResult[1]
Executing ChallengeResult with authentication schemes().
info: Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler[2]
Executed action ThingsProjectorWeb.Controllers.HomeController.Index in 0ms
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[2]
Request finished in 0.0016ms 401
任何关于如何正确配置这个帮助将不胜感激。谢谢!
这不工作的IISIntergration。在Kestrel上,我得到了一个完美的302,但是在IIS上,我得到了一个401。有没有什么可以让它在IISIntergration上工作的呢? –
@MitchDart可能是IIS默认为FormsAuthentication。尝试添加 到web配置? –
Strake
这对我来说也不适用。坚持尝试重定向两天。你需要在此之前添加一项服务吗?我有:services.AddSession();这应该增加对此的支持。已经厌倦了Core。它只是不起作用。 – Sam