I'm working on moving an existing Web API from IIS to NGINX with Mono and I'm stuck on default error pages: whatever I do, I still get default one, which exposes confidential data: system, ASP.NET version and Powered by
Default 404 error page on Mono
I already tried to add customErrors
element under system.web
configuration, but that didn't help (I guess it would work for MVC application). Here's my current config:
<system.web>
<compilation debug="false" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" enableVersionHeader="false" />
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Auto" defaultPath="/Error/500" defaultResponseMode="ExecuteURL">
<remove statusCode="403"/>
<error statusCode="403" path="/Error/404" responseMode="ExecuteURL"/>
<remove statusCode="404"/>
<error statusCode="404" path="/Error/404" responseMode="ExecuteURL"/>
</httpErrors>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
</system.webServer>
The code I tried:
<system.web>
...
<customErrors mode="On" defaultRedirect="~/Error/500" redirectMode="ResponseRewrite">
<error statusCode="403" redirect="~/Error/404" />
<error statusCode="404" redirect="~/Error/404" />
</customErrors>
</system.web>
The error endpoint work properly, because when I navigate manually to these addresses then I get a correct response
It seems like Mono (FastCGI) does not use the httpErrors
configuration which is working for IIS
There's also existingResponse="Auto"
which makes responses with TrySkipIisCustomErrors
flag passing to user without being transformed to custom page. What should I do to make Mono behave like IIS?