我在 Action Method 上使用了 Authorize 属性,是否需要检查用户是否已通过身份验证?

I used Authorize attribute on Action Method ,do I need to check that User Is Authenticated or not?

下面的代码是我在 Asp.Net 核心 3 中的操作方法。

[HttpGet]
[Authorize]
public async Task<IActionResult> Info()
{
    if (!User.Identity.IsAuthenticated) /// Is this need?
    {
         return BadRequest("Un Authorized Access");
    }
 }

我在 method.Do 上使用了 Authorize 属性我需要用 User.Identity.IsAuthenticated 再次检查用户的身份验证 ?

你应该看看 "Authentication versus Authorization" 之间的区别,见

您发布的代码还不够,因为有时用户即使未通过身份验证也满足授权要求。


我的答案是错误的,请查看 Joe 的评论并指出 https://github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Http/AuthorizeAttribute.cs [Authorize] 属性还检查身份验证