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
Post a Comment