2

出于安全原因,我想忽略/禁止所有查询字符串参数。

IE

POST http://myservice/person
{name:"john"}
//should populate the Name property in my request model


POST http://myservice/person?name=john
//should NOT populate the Name property

如果不明确检查每个服务方法中的查询字符串,这可以在服务堆栈中实现吗?

我想这样做是因为某些服务器会在 SSL 解码后以纯文本形式记录 URL,并且我想确保敏感参数值不会记录在任何托管环境中。

4

1 回答 1

2

如果您希望全局应用任何逻辑,您可以使用全局过滤器或在任何其他过滤PreRequestFilter或请求绑定之前运行的 a :

this.PreRequestFilters.Add((req, res) =>
{
    if (req.QueryString.Count > 0)
    {
        res.StatusCode = (int)HttpStatusCode.BadRequest;
        res.StatusDescription = "Query Strings are not allowed";
        res.EndServiceStackRequest();
    }
});
于 2013-04-24T00:30:01.433 回答