asp.net - .NET MVC throws 500 Server Error instead of 404 Not Found when cannot match a Controller path -


for reason, when entering dud url file/directory/controller not exist, following error thrown:

system.web.httpexception controller path '' not found or not implement icontroller system.web.mvc.icontroller > getcontrollerinstance(system.web.routing.requestcontext, system.type)

iis follows regular error handling , shows page appropriate 500 internal server error. 404 not found error handling logic should followed. another web application testing on not throw httpexception when can't find route, , returns 404 normally. triggeres httpexception?

why , how follow 404 route type of error instead of 500? below configuration of error handling. no other code handling errors. why 500 error shown. it's if default handling handles 'can't find controller' exception error when in fact it's not-found.

<system.webserver>  <httperrors errormode="custom" existingresponse="replace" defaultpath="/staticerrors/default.html" defaultresponsemode="executeurl">    <clear />    <error statuscode="404" path="/mvcerror/http404" responsemode="executeurl" />        <error statuscode="500" path="/mvcerror/http500" responsemode="executeurl" />       </httperrors> </system.webserver> <system.web>  <customerrors defaultredirect="/staticerrors/default.html" mode="on" redirectmode="responserewrite">    <error redirect="/mvcerror/http404" statuscode="404" />              <error redirect="/mvcerror/http500" statuscode="500" />           </customerrors> </system.web> 

failed request trace shows this. since no route round, httpexception thrown, , 500 route handling kicks in, instead of 404. i'm not doing overide normal default behaviour. handleerrorattribute not being added either mvc filters.

enter image description here

you should add filter controller override iis custom error.

public class mvcerrorcontroller : controller    {     public actionresult http404()     {     response.statuscode = 404;     response.tryskipiiscustomerrors = true;      return view();    } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -