My understanding is that if you added app.UseExceptionHandler(); and gave him the way ASP.Net should load this page when there is an error that didn’t get into the code, but in my case I still get the normal "Http 500 Internal Server Error". I can take the path that I give UseExceptionHandler() , and put it directly in my browser, and it loads the page so that I know that the path and page are working. Am I lacking in understanding how this works, is it broken, or am I something wrong?
Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); //} app.UseExceptionHandler("/Error/ServerError"); app.UseIISPlatformHandler(); app.UseSession(); app.UseStaticFiles(); app.UseStatusCodePagesWithReExecute("/Error/PageNotFound"); app.UseMvc(); }
Error Page Code:
//Get: "/Error/ServerError" [Route("Error/ServerError")] public IActionResult ServerError() { return View(); //View is inside the Shared folder. }
View error page:
<p> @ViewData["ErrorMessage"] </p>
Please note that the "Page not found" errors are redirected to /Error/PageNotFound without problems, these are just other errors.
EDIT: As a test, I copied the line from UseStatusCodePagesWithReExecute to UseExceptionHandler , but still get a 500 common error page.
Edit 2: I have to note that I test this error in two ways. The first is a simple action throw new DivideByZeroException(); and the other in calling LINQ to Entities to a database that was offline offline (and as such throws a SqlException ). Both methods simply return the default HTTP 500 Internal Server Error , not my custom error.
source share