2

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();
     }
});
moath naji
  • 663
  • 1
  • 4
  • 20

1 Answers1

2

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) => {
    //...
});
mythz
  • 141,670
  • 29
  • 246
  • 390
  • its not fired up filter when i hit login so i cant detect the request or the dto – moath naji May 08 '17 at 12:22
  • @moathnaji I don't understand what you're saying? The Global Request Filter gets called for each Service Request, if the client is making an `Authenticate` request it will get called. – mythz May 08 '17 at 12:28
  • still get it null requestDto >> attributes come's null – moath naji May 08 '17 at 12:44
  • @moathnaji it's impossible to get a `null` requestDto, if it's not populated that's a different issue and you'll need to make sure the Service is called correctly. – mythz May 08 '17 at 12:46
  • @moathnaji that just means the request which executed the filter was not an `Authenticate` Request DTO, you should be able to tell what Type the Request DTO is from the debugger or you can get the name with `requestDto.GetType().Name`. – mythz May 08 '17 at 12:51