1

在 ServiceStack 项目中,我添加了 api 密钥授权,如下所示

this.RequestFilters.Add((req, res, dto) =>
{
    var apiKey = req.Headers["X-ApiKey"];
    if (apiKey == null || !ApiKeyValidation.VerifyKey(apiKey))
    {
        throw HttpError.Unauthorized("Unknown ApiKey");
    }
});

通过 REST 访问服务时,我得到了预期的响应:

{
    "ResponseStatus": {
        "ErrorCode": "Unknown ApiKey",
        "Message": "Unknown ApiKey"
    }
}

访问 SOAP 1.2 端点时,我从 IIS 服务器收到 HTML 响应,其中包含错误消息和堆栈跟踪。这似乎也发生在其他(输入字符串格式不正确)错误中。

Unknown ApiKey

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: ServiceStack.Common.Web.HttpError: Unknown ApiKey

我的 DTO 是这样写的:

[DataContract]
public class UserDetails : IReturn<UserDetailsResponse>
{
    [DataMember]
    public string Email { get; set; }
}

[DataContract]
public class UserDetailsResponse
{
    [DataMember]
    public Account User { get; set; }
    [DataMember]
    public ResponseStatus ResponseStatus { get; set; }
}

我在配置中设置了 DebugMode = false。我错过了一些配置选项吗?

4

0 回答 0