IIS overwrites body of Express response

182 views Asked by At

I have an express app which runs under iisnode. When Express returns a response with status 401 there is attached JSON with an error message.

res.status(401).json({message: "error text"});

When I try it in the browser the status is ok but response contains some other message instead of the JSON. The message is "You do not have permission to view this directory or page."

(At first, the response contained predefined error document, which I deleted from Error Pages in IIS settings. )

When Express returns status 2xx everything is ok.

So, it seems that IIS overwrite JSON by text message when the request fails. I made some research and find response property TrySkipIisCustomErrors but it doesn't work. https://msdn.microsoft.com/en-us/library/system.web.httpresponse.tryskipiiscustomerrors.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

Has someone idea how to disable this behavior?

1

There are 1 answers

0
Grimbot On

For anyone else landing here the solution for me was:

<httpErrors errorMode="Custom" existingResponse="PassThrough"></httpErrors>