Gateway and PreRequestFilters

I have an MVC app running ServiceStack, I also have added a pre-request filter in appHost.PreRequestFilters, and all is good when I make an API call on a route like /api/something, from PostMan, the pre request filter is run just fine. (it does some CSRF checks).

Now, I add an addtional MVC POST action on route /somethingelse, and in there I do some minimal processing, where I want to call my ServiceStack service (the one at /api/something).

As recommended, I am using the Gateway of my controller to forward the call to my API, and it does forward the call to my ServiceStack service, but, in this case the PreRequestFilter are bypassed!

        [Microsoft.AspNetCore.Mvc.Route("/somethingelse")]
        public IActionResult DoSomethingElse(string stuff)
        {
            try
            {
                // This next call bypasses my PreRequestFilters
                Gateway.Send(new DoSomethingRequest
                {
                    Stuff = stuff,
                });
            }
            catch (Exception ex)
            {
                return Problem(ex.Message, null, ex.ToStatusCode());
            }

            return Redirect("/");
        }

Can you advise how to make this Gateway call trigger the PreRequestFilters? or is not the right pattern to use?

The PreRequestFilters only get fired for an external request, you would instead use GatewayRequestFilters/Async to register & executing custom logic for Service Gateway requests.

You could invoke the PreRequestFilters manually with HostContext.AppHost.ApplyPreRequestFilters() however that’s only going to execute filters on the original IRequest again.