首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AuthorizeAttribute重定向到拒绝访问的页面,即使已记录

AuthorizeAttribute重定向到拒绝访问的页面,即使已记录
EN

Stack Overflow用户
提问于 2016-08-16 17:50:44
回答 1查看 4.8K关注 0票数 2

Startup.cs:

代码语言:javascript
运行
复制
        app.UseCookieAuthentication(new CookieAuthenticationOptions()
        {
            AuthenticationScheme = "CustomAuthenticationCookieMiddleware",
            LoginPath = new PathString("/user/login"),
            LogoutPath = new PathString("/user/logout"),
            AccessDeniedPath = new PathString("/access-denied"),
            AutomaticAuthenticate = true,
            AutomaticChallenge = true
        });

MembershipController.cs

代码语言:javascript
运行
复制
...
await HttpContext.Authentication.SignInAsync("CustomAuthenticationCookieMiddleware", claimsPrincipal, new AuthenticationProperties { IsPersistent = loginUser.RememberMe });
...

========

问题:

[Authorize]属性不工作。它重定向到拒绝访问的页面。

但是[Authorize(Roles = "Administrator")]运行得很好

注意:即使我成功登录,"User.Identity.IsAuthenticated"也总是错误的。

EN

回答 1

Stack Overflow用户

发布于 2016-08-20 08:42:32

我引用如下:

类似地,对于禁止的响应,当我们将中间件添加到管道时,用户将被重定向到AccessDeniedPath中指定的路径。在本例中,我们不重定向到登录路径,因为用户已经通过身份验证,他们只是没有正确的声明或权限来查看所请求的资源

阅读这篇优秀的文章并解决您的问题:https://andrewlock.net/exploring-the-cookieauthenticationmiddleware-in-asp-net-core/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38981382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档