c# - Not Passing Through Application Error When Controller Doesn't Exist -


i want use application_error() in global.asax log bad url's on website , redirect custom error landing page. problem why website not passing through application error when controller doesn't exist.

i tested following url's , passed through application error:

this 1 doesn't pass through application error , returns 404:

application error code:

protected void application_error(object sender, eventargs e) {      var requesttime = datetime.now;      exception ex = server.getlasterror().getbaseexception();      //log request.url.tostring() } 

routeconfig.cs code:

routes.ignoreroute("{resource}.axd/{*pathinfo}");  routes.maproute(     name: "account",     url: "account/{action}/{id}",     defaults: new { controller = "account", action = "index", id = urlparameter.optional } );  routes.maproute(     name: "home",     url: "home/{action}/{test}",     defaults: new { controller = "home", action = "index", id = urlparameter.optional } );  routes.maproute(     name: "homeblank",     url: "",     defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); 

please add following routeconfig.cs :

routes.maproute(     name: "notfound",     url: "{*url}",     defaults: new { controller = "error", action = "notfound", id = urlparameter.optional } ); 

some urls fail parsed , adding above handle these cases. in action notfound of errorcontroller, can show user custom error page.

public class errorcontroller : controller {     public actionresult notfound()     {         response.statuscode = 404;         return view();     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -