我可以调用 Context.SetError 两次来返回 2 个值吗?

Can I call Context.SetError twice to provide 2 values back?

作为这个问题的后续问题:

OWIN Web api 2 adding additional logic to Bearer authorization

我可以像下面那样调用 context.SetError 两次,将 2 个值返回给请求者吗?如果不是,正确的方法是什么?

        if (user == null)
        {
            context.SetError("invalid_grant", "The user name or password is incorrect.");
            context.SetError("error_code", 69);

            return;
        }

好的,对于那些通过未来搜索引擎访问的人:

没有。您不能调用它两次来返回 2 个值。我最终只是将我想说的内容连载(To Json)并塞入error_description字段。一个只有半个大脑的开发人员能够将它解释回一个对象并适当地使用它。

你说得对,你不能调用它两次。 我发现这个类似问题的答案对我来说非常有用:

我需要添加 error_code 除了 errorerror_description 所以我扩展了 OAuthGrantResourceOwnerCredentialsContext 就像 user2325333 的例子一样。