I would like to have 1 error page, which, depending on the query line, displays a slightly different error message to the user.
I noticed the following code in the Startup.cs file when creating a new asp.net 5 project.
if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); }
I was able to get this to display the correct error page when an exception occurs. My problem is that they seem to catch errors that were not handled in my application, i.e. always with a status code of 500 . It's right?
To handle 404 errors, I use the following code:
app.UseStatusCodePagesWithReExecute("/Error/{0}");
With my controller implemented as:
[HttpGet("{statusCode}")] public IActionResult Error(int statusCode) { return View(statusCode); }
It seems to catch 404 errors and display the correct status code.
If I update my code in the above if statement to use the same action, for example:
if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error/{0}"); }
The returned status code is always 0.
Also, what happens when a 400 , 403 or whatever happens? Will they be caught? If so, at what point will they be caught?
As you can tell, I am very confused and would like someone to provide me with an example where all the different status codes are processed.
Cool breeze
source share