NotFound page is not shown if HttpError.NotFound was thrown

It seems to me there is an issue with the CustomErrorHttpHandlers and the RazorHandler in v5.0.0

Please try this to reproduce:

  1. Create a new starter project with the “ServiceStack ASP.NET Razor with Bootstrap” template
  2. Create a simple new endpoint, which just throws a HTTPError ( throw HttpError.NotFound("…"); )
  3. Request the endpoint with a browser.

I expect to see the NotFound page, since there is this configuration statement:

CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new RazorHandler("/notfound");

Everything works fine up to v.4.5.15. But with v5.0.0 (up to v5.0.3) the result is a blank page. No bytes in the body.

Also it still works fine if I request an unknown URL.

I don’t know, what goes wrong here. I just noticed that the response is already closed in the method ProcessRequest from the RazorHandler.

Any ideas?

This should now be resolved with this commit from v5.0.3 that’s now available on MyGet.

No, it is not resolved. As I mentioned, v5.0.3 also results in a blank page.

Could you please try to reproduce this issue?

Of course I reproduced the issue, which was how I could have been able to commit a fix. If you previously had v5.0.3 downloaded you will need to clear your NuGet cache with:

$ nuget locals all -clear

Then delete the /packages folder before installing v5.0.3 packages again.

I’ve published the repro project to which contains the NotFound Razor Handler:

CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new RazorHandler("/notfound");

And a services which throws a Not Found Error response:

public class Throw404 { }

public class MyServices : Service
    public object Any(Hello request)
        return new HelloResponse { Result = $$"Hello, {request.Name}!" };

    public object Any(Throw404 request)
        throw HttpError.NotFound("Not here");

Where if you go to /throw404 will render this page:

If you’ve found a different issue please submit a pull request to the CustomErrorHandlerTest project which shows the issue.

1 Like

Oh sorry, you are right! I forgot to clear the cache. I didn’t realize, that this was a newer commit.

Thank you!