【问题标题】:servicestack routing - how do you ignore the query string parametersservicestack 路由 - 你如何忽略查询字符串参数
【发布时间】:2013-04-17 08:23:33
【问题描述】:

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

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,并且我想确保敏感参数值不会记录在任何托管环境中。

【问题讨论】:

    标签: routing servicestack


    【解决方案1】:

    如果您希望全局应用任何逻辑,您可以使用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();
        }
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2017-09-01
    相关资源
    最近更新 更多