asp.net core mvc - Unhandled expections in are not being routed to my custom error page -


my understanding if added app.useexceptionhandler(); , give path asp.net supposed load page when ever there error not caught in code in case still getting normal "http 500 internal server error" page. can take path give useexceptionhandler() , put right in browser , load page fine know path , page work. miss understanding how work, broken, or doing 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 inside shared folder. } 

error page view:

<p>     @viewdata["errormessage"] </p> 

please note "page not found" errors routed /error/pagenotfound no problems, other errors not.

edit: test copied string usestatuscodepageswithreexecute useexceptionhandler still generic 500 error page.

edit 2: should note testing error in 2 ways. first having action throw new dividebyzeroexception(); , other have linq entities call database has been taken offline (and such throwing sqlexception). both ways return default http 500 internal server error , not custom error.

i thought ordering of usexxx functions important, testing proved incorrect.

the way able example working modify error page code following:

[route("error/servererror")] public iactionresult servererror() {     return view("error/servererror"); } 

this assumes following exists: [projectdir]\views\shared\error\servererror.cshtml

if set view name "servererror" , have view located @ [projectdir]\views\shared\servererror.cshtml, there appears bug in either microsoft.aspnet.diagnostics or microsoft.aspnet.mvc package.

when erroneous request made, following written log:

info: microsoft.aspnet.mvc.controllers.controlleractioninvoker[1]       executing action method webapplication2.controllers.errorscontroller.get arguments () - modelstate valid' fail: microsoft.aspnet.mvc.viewfeatures.viewresultexecutor[0]        view 'servererror' not found. searched locations: /views/errors/servererror.cshtml, /views/shared/servererror.cshtml fail: microsoft.aspnet.diagnostics.exceptionhandlermiddleware[0]       exception thrown attempting execute error handler.       system.invalidoperationexception: view 'servererror' not found. following locations searched:       /views/errors/servererror.cshtml       /views/shared/servererror.cshtml. 

the log states attempt made locate view @ /views/shared/servererror.cshtml. yet request fails , uses default error handler.

this issue has been logged on aspnet/diagnostics github repository here.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -