servicestack routing - 如何忽略查询字符串参数

时间:2013-04-23 23:30:55

标签: routing servicestack

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

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

这可以在sevicestack中实现,而无需在每个服务方法中明确检查查询字符串吗?

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

1 个答案:

答案 0 :(得分:2)

如果您想要全局应用任何逻辑,可以使用global filterPreRequestFilter gets run before any other filter or request binding

this.PreRequestFilters.Add((req, res) =>
{
    if (req.QueryString.Count > 0)
    {
        res.StatusCode = (int)HttpStatusCode.BadRequest;
        res.StatusDescription = "Query Strings are not allowed";
        res.EndServiceStackRequest();
    }
});