【发布时间】:2016-05-01 13:50:55
【问题描述】:
我正在尝试在 Asp.net 核心应用程序 (dnx 4.5) 中使用 cookie 身份验证。请注意,因为我有一个自定义身份验证机制(半径),所以我没有使用 core Authentication 提供的开箱即用机制。当用户未通过身份验证时,我想重定向到登录页面。
我在 Startup.cs 中添加了以下代码。这个想法是在用户尚未通过身份验证时重定向到登录控制器:
app.UseCookieAuthentication(options => { options.LoginPath = new Microsoft.AspNet.Http.PathString("/Login"); });
在我的 Home 控制器中,我有:
[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
任何有关如何正确配置的帮助将不胜感激。谢谢!
【问题讨论】:
标签: asp.net-core asp.net-core-mvc