我希望在用户访问[Autorize]控制器时重定向用户。
我正在使用UseCookieAuthentication。它工作得很好,但LoginPath不会重定向我的请求。我总是得到" 401 Unauthorized" (即空页)。
在我的代码下面:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookie",
CookieName = "bearerCookies",
TicketDataFormat = new CustomJwtDataFormat(SecurityAlgorithms.HmacSha256, tokenValidationParameters),
LoginPath = new PathString("/Account/Login"),
AutomaticAuthenticate = true,
AutomaticChallenge = true,
});
但是我试着像这篇帖子一样添加事件:Modify CookieAuthenticationOptions LoginPath OnRedirectToReturnUrl Event我甚至在这个事件中设置了断点,我没有输入这个函数!
我也尝试过这种方式ASP Identity in MVC6 - Login Path property not working
但是对于aspnetcore来说并不固定。我也在更新我的包,正如我在一些论坛上看到的那样
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.AspNetCore.Authentication.OAuth": "1.1.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.1.0",
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.1",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.1.1",
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0"
谁有人遇到这个问题?你知道吗?我只想要一个简单的重定向:)
谢谢大家