Francois Taljaard
Francois Taljaard

Reputation: 1477

ServiceStack original Request DTO after Filter manipulation

Good day, is there a way to get the original request DTO in the response filter. In my request filter I manipulate the values of the 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.

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. Also the request reflects the new values.

Upvotes: 0

Views: 507

Answers (1)

mythz
mythz

Reputation: 143399

The IRequest.OriginalRequest and IResponse.OriginalResponse lets you get the underlying ASP.NET HttpRequestBase or HttpListenerRequest objects.

Instead you can get it from the IRequest.Dto property, e.g:

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

Upvotes: 2

Related Questions