WebAPI AuthorizeAttribute with Protobuf returns 500

本文关键字:returns Protobuf with AuthorizeAttribute WebAPI | 更新日期: 2023-09-27 18:14:20

我有一个问题已经困扰了我一段时间了。我已经设法尽可能多地减少。

我有一个标准System.Web.Http.ApiController,其中包含一个仅返回Ok();的 Get 方法

控制器标有[WindowsAuthorize],这是自己创建的自定义属性。目前,此属性简化为:

public class WindowsAuthorizeAttribute : AuthorizeAttribute
{
    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        return false;
    }
}

现在,使用 Postman,当我使用以下标头向我的端点发出GET请求时,我得到:

Accept: application/json
//Status: 401, Body: { "Message": "Authorization has been denied for this request."}

相同的请求,但带有 protobuf 标头:

现在,使用 Postman,当我使用以下标头向我的端点发出GET请求时,我得到:

Accept: application/x-protobuf
//Status: 500, Body: (empty)

不知何故,401变成了500 Internal Server Error,但我没有得到服务器端的异常。我在这里做错了什么,还是如何调试?

如果我错了,请纠正我,但正确的行为是返回401,然后客户端应该在启用 NTLM 身份验证的情况下重试,对吗?(假设注释了完整的代码(

WebAPI AuthorizeAttribute with Protobuf returns 500

问题是每当发送一个主体时 - 在这种情况下{ "Message": "Authorization has been denied for this request."},它也需要是可序列化的 protobuf。