Search code examples
c#.netservicestack

servicestack GlobalRequestFilters request Dto coming null


I have a ServiceStack GlobalRequestFilters filter in the apphost file that catch the authenticate request, the filter is working fine but the problem is in the dto in req , res and requestDto is null!

this.GlobalRequestFilters.Add((req, res, requestDto) => {
     if (req.OperationName.ToLower()== "authenticate")
     {
         var authData =req.GetDto();
     }
});

Solution

  • The requestDto is passed in the filter itself, i.e:

    GlobalRequestFilters.Add((req, res, requestDto) => {
        var authDto = requestDto as Authenticate;
        if (authDto != null)
        {
            //...
        }
    });
    

    An alternative approach to the above is to use a Typed Request Filter, e.g:

    RegisterTypedRequestFilter<Authenticate>((req, res, authDto) => {
        //...
    });