更新时间:2023-02-15 22:41:14
对于 Web API,您应该使用 System.Web.Http.dll 中的 System.Web.Http.AuthorizeAttribute
而不是 System.Web.Mvc.AuthorizeAttribute
.
You should use System.Web.Http.AuthorizeAttribute
from System.Web.Http.dll for Web API instead of System.Web.Mvc.AuthorizeAttribute
.
也就是说,因为 namespace System.Web.Http.AuthorizeAttribute
派生自 AuthorizationFilterAttribute
.过滤器由 Web API 自动处理.在我自己的实现中,我直接从 AuthorizationFilterAttribute
派生而来,用于处理基本的 HTTP 身份验证.
That is, because namespace System.Web.Http.AuthorizeAttribute
is derived from AuthorizationFilterAttribute
. The filters are handled automatically by the Web API. In my own implementation I derived directly from AuthorizationFilterAttribute
for handling of the basic HTTP authentication.