Redirect ASPCore,重定向失败CookieAuthenticationOptions登录路径
当用户想要访问[自动调整大小]控制器时,我想重定向用户 我正在使用UseCookie身份验证。它的工作很好,但LoginPath没有重定向我的请求。我总是得到“401未经授权”(即空页) 下面是我的代码:Redirect ASPCore,重定向失败CookieAuthenticationOptions登录路径,redirect,asp.net-core,Redirect,Asp.net Core,当用户想要访问[自动调整大小]控制器时,我想重定向用户 我正在使用UseCookie身份验证。它的工作很好,但LoginPath没有重定向我的请求。我总是得到“401未经授权”(即空页) 下面是我的代码: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = "Cookie", CookieName = "bearer
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookie",
CookieName = "bearerCookies",
TicketDataFormat = new CustomJwtDataFormat(SecurityAlgorithms.HmacSha256, tokenValidationParameters),
LoginPath = new PathString("/Account/Login"),
AutomaticAuthenticate = true,
AutomaticChallenge = true,
});
但我试着添加这样的事件:我甚至在这个事件中设置了断点,我不在这个函数中输入
我也试过这种方法
但对于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"
有人知道这个问题吗?你知道吗?我只需要一个简单的重定向:)
谢谢大家您在登录路径/控制器上有
[AllowAnonymous]
吗?或者是浏览器中根本没有重定向(检查F12工具)?您好,是的,是的,我有[AllowAnonymous]
,当我检查F12时,我看到(401 Unauthorized
)。完全没有重定向:S