简体   繁体   English

筛选器操作后,ServiceStack原始请求DTO

[英]ServiceStack original Request DTO after Filter manipulation

Good day, is there a way to get the original request DTO in the response filter. 美好的一天,有没有办法在响应筛选器中获取原始请求DTO。 In my request filter I manipulate the values of the DTO. 在请求过滤器中,我操纵DTO的值。

 appHost.GlobalRequestFilters.Add((req, res, reqDto) =>
        {
            if (reqDto is Granite.Webservice.Resources.MasterItemRequest)
            {
                string code = ((Granite.Webservice.Resources.MasterItemRequest)reqDto).Code;
                ((Granite.Webservice.Resources.MasterItemRequest)req.Dto).Code = code.Replace("^", "");
            }
        });

In the above code you can see I change the Code to exclude ^ character. 在上面的代码中,您可以看到我将代码更改为排除^字符。 Take note this is a example and not the actual implementation so don't ask why ^ is appearing. 请注意,这只是一个示例,而不是实际的实现,因此请不要问为什么出现^。

Then in my response I would like to get the original value of the request and the property Code. 然后在响应中,我想获取请求的原始值和属性Code。

My response filter: 我的回应筛选器:

        appHost.GlobalResponseFilters.Add((req, res, reqDto) =>
        {
            var t = req.OriginalRequest;

        });

If I look at the req OriginalRequest it does not have the DTO. 如果我查看req OriginalRequest的请求,它没有DTO。 Also the request reflects the new values. 该请求还反映了新值。

The IRequest.OriginalRequest and IResponse.OriginalResponse lets you get the underlying ASP.NET HttpRequestBase or HttpListenerRequest objects. IRequest.OriginalRequestIResponse.OriginalResponse使您可以获取基础ASP.NET HttpRequestBase或HttpListenerRequest对象。

Instead you can get it from the IRequest.Dto property, eg: 相反,您可以从IRequest.Dto属性获取它,例如:

appHost.GlobalResponseFilters.Add((req, res, resDto) => {
    var dto = req.Dto;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM