下面的代码是我在Asp.Net Core 3中的操作方法。
[HttpGet]
[Authorize]
public async Task<IActionResult> Info()
{
if (!User.Identity.IsAuthenticated) /// Is this need?
{
return BadRequest("Un Authorized Access");
}
}
我在方法上使用了Authorize
属性。是否需要使用User.Identity.IsAuthenticated
再次检查用户的身份验证?
答案 0 :(得分:1)
您应该查看“身份验证与授权”之间的区别,请参见https://stackoverflow.com/a/6556548/2219991
您发布的代码是不够的,因为即使用户未通过身份验证,有时也会满足授权要求。
我的回答是错误的,请查看Joe的评论,并指出https://github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Http/AuthorizeAttribute.cs的if(ariaExpanded.equalsIgnoreCase("false")) {
xpathToLi.findElement(By.xpath("./span[@role='presentation']")).click();
}
属性还会检查身份验证