c# - Confused with error handling in ASP.net 5 MVC 6 -


i have 1 error page depending on query string provided displays different error message user.

i have noticed following code in the startup.cs file when creating new asp.net 5 project.

if (env.isdevelopment()) {     app.usebrowserlink();     app.usedeveloperexceptionpage(); } else {     app.useexceptionhandler("/home/error"); } 

i have been able display correct error page when exception occurs. issue seems catch errors have not been handled in application i.e. status code of 500. correct?

to handle 404 errors using following code:

app.usestatuscodepageswithreexecute("/error/{0}");  

with controller implemented as:

[httpget("{statuscode}")] public iactionresult error(int statuscode) {     return view(statuscode); } 

this seems catch 404 errors , displays correct status code.

if update code in above if statement use same action example:

if (env.isdevelopment()) {     app.usebrowserlink();     app.usedeveloperexceptionpage(); } else {     app.useexceptionhandler("/error/{0}"); } 

the status code returned 0.

in addition happen when 400, 403 or other occurs? caught? if @ point caught?

as can tell confused , love provide me example different status codes handled.

it sounds you're confusing unhandled exceptions (which are, default, returned client http 500 internal server error) , correctly-handled error cases caused invalid action on behalf of user/client (where 4xx http code returned user).

only former of these has useexceptionhandler call - default catch unhandled exceptions , route them whatever provide (in case, view, piece of code inspects unhandled exceptions convert error cases http 4xx return codes - example, authentication errors http 401 responses).

usestatuscodepageswithreexecute step in status code has been generated of 400-599, long no response body has been generated already. source code in question shows how determined.

in second code block, you've used useexceptionhandler - think should have following:

if (env.isdevelopment()) {     app.usebrowserlink();     app.usedeveloperexceptionpage(); } else {     // handle unhandled errors     app.useexceptionhandler("/home/error");     // display friendly error pages non-success case     // handle situation status code >= 400     // , < 600, long no response body has been     // generated.     app.usestatuscodepageswithreexecute("/error/{0}");  } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -