How to prevent IIS from overriding custom error pages with IIS default error pages? Is there a Response.TrySkipIisCustomErrors equivalent for asp.net core? In ASP Net MVC I use the code below to send error without a custom page but in asp net core it is not working.
try
{
// some code
}
catch (Exception ex)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
mensagem = ex.Message;
}
ASP.NET Core doesn't include an equivalent type. Support for HttpResponseException can be added with the following steps: The preceding filter specifies an Order of the maximum integer value minus 10. This Order allows other filters to run at the end of the pipeline.
You can set this TrySkipIisCustomErrors property anytime before the Response gets sent out to IIS - ie. anytime before any output is sent explicitly. If you use Response.TrySkipIisCustomErrors alone you'll find that even with the flag set to true, the response still fires IIS errors rather than the content you return.
In ASP.NET Core, returning status code is easier than you might think. HTTP response status codes have so much importance in REST API’s. In any case if you want to return a status code from your ASP.NET Core API, all you have to do is in your controller method,
Response compression in ASP.NET Core. Network bandwidth is a limited resource. Reducing the size of the response usually increases the responsiveness of an app, often dramatically. One way to reduce payload sizes is to compress an app's responses.
It sounds like you're trying to disable the status code error pages for a particular request. The ASP.NET Core documentation for Handling Errors gives you the answer.
It's not as succinct as the old TrySkipIisCustomErrors
flag, but may be clearer what's actually going on:
var statusCodePagesFeature =
HttpContext.Features.Get<IStatusCodePagesFeature>();
if (statusCodePagesFeature is not null)
{
statusCodePagesFeature.Enabled = false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With