ASP.NET Core equivalent of ASP.NET MVC 5’s HttpException

I implemented my own HttpException and supporting middleware which catches all HttpException‘s and turns them into the corresponding error response. A short extract can be seen below. You can also use the Boxed.AspNetCore Nuget package. Usage Example in Startup.cs public void Configure(IApplicationBuilder application) { application.UseIISPlatformHandler(); application.UseStatusCodePagesWithReExecute(“/error/{0}”); application.UseHttpException(); application.UseMvc(); } Extension Method public static class ApplicationBuilderExtensions … Read more

Why do I get “Cannot redirect after HTTP headers have been sent” when I call Response.Redirect()?

According to the MSDN documentation for Response.Redirect(string url), it will throw an HttpException when “a redirection is attempted after the HTTP headers have been sent”. Since Response.Redirect(string url) uses the Http “Location” response header (http://en.wikipedia.org/wiki/HTTP_headers#Responses), calling it will cause the headers to be sent to the client. This means that if you call it a … Read more

Catching “Maximum request length exceeded”

There is no easy way to catch such exception unfortunately. What I do is either override the OnError method at the page level or the Application_Error in global.asax, then check if it was a Max Request failure and, if so, transfer to an error page. protected override void OnError(EventArgs e) ….. private void Application_Error(object sender, … Read more