mylvgth
mylvgth

Reputation: 49

ServiceStack Razor Response Filter

I Write a ServiceStack Razor Page named 'default.cshtml'. I want to add a global response filter on it running, but it not work right. how to fixed it?

enter image description here

    private static void AddFilters(IAppHost appHost)
    {
        appHost.GlobalResponseFilters.Add((req, res, dto) =>
        {
           res.AddHeader("X-Powered-By", "mylvgth");
         });
     }

Upvotes: 1

Views: 42

Answers (1)

mythz
mythz

Reputation: 143319

GlobalResponseFilters are for requests that populate Request DTOs and are executed by Services. For other requests you can use PreRequestFilters which is executed at the start of a Request.

There are no Response filters for Razor pages as you can’t add Headers to a Request after its already written to the Response, only for “View Pages” which call Services first where the Response filter is executed before the page is rendered.

Upvotes: 2

Related Questions