Authentication 在WebAPI中,Authorize属性默认做什么?
我猜默认情况下,[Authorize]属性检查实现IPrincipal的非空对象 我走对了吗 我走对了吗 是的,你是。更确切地说,您可以查看如何实现[授权]: 我走对了吗 是的,你是。更确切地说,您可以查看如何实现[授权]:Authentication 在WebAPI中,Authorize属性默认做什么?,authentication,asp.net-web-api,iprincipal,Authentication,Asp.net Web Api,Iprincipal,我猜默认情况下,[Authorize]属性检查实现IPrincipal的非空对象 我走对了吗 我走对了吗 是的,你是。更确切地说,您可以查看如何实现[授权]: 我走对了吗 是的,你是。更确切地说,您可以查看如何实现[授权]: 谢谢,我完全忘了WebAPI是开源的,我可以看一下代码。谢谢,我完全忘了WebAPI是开源的,我可以看一下代码。 protected virtual bool IsAuthorized(HttpActionContext actionContext) { if (a
谢谢,我完全忘了WebAPI是开源的,我可以看一下代码。谢谢,我完全忘了WebAPI是开源的,我可以看一下代码。
protected virtual bool IsAuthorized(HttpActionContext actionContext)
{
if (actionContext == null)
{
throw Error.ArgumentNull("actionContext");
}
IPrincipal user = Thread.CurrentPrincipal;
if (user == null || !user.Identity.IsAuthenticated)
{
return false;
}
if (_usersSplit.Length > 0 && !_usersSplit.Contains(user.Identity.Name, StringComparer.OrdinalIgnoreCase))
{
return false;
}
if (_rolesSplit.Length > 0 && !_rolesSplit.Any(user.IsInRole))
{
return false;
}
return true;
}