Stop exception from being thrown for non-existent controller

前端 未结 4 1462
攒了一身酷
攒了一身酷 2021-02-15 09:50

Ok, so I am stumped on this issue. I have seen a lot of things that are supposed to resolve this issue, but I am not getting a resolution that can fulfill my requirements.

相关标签:
4条回答
  • 2021-02-15 10:37

    Wire up a custom controller factory that can execute your desired features when it fails to locate the requested controller. It's just a few lines of code, nothing too painful.

    You can roll your own controller factory, or use one of the many libraries as a starting point. You'll have a class that implements IControllerFactory and inside the CreateController() function will be your custom logic.

    0 讨论(0)
  • 2021-02-15 10:42

    Was probably not relaying my issue properly, after tons of digging around this exception is supposed to be thrown. The answer is to exclude those exceptions from ELMAH, according to this article.

    By default, ELMAH logs the details of every unhandled exception, including 404 and other HTTP errors. You can instruct ELMAH to ignore these or other types of errors using error filtering.

    0 讨论(0)
  • 2021-02-15 10:46

    Create a RouteConstraint, that checks if the controller exists (in fact, scans all possible controllers in beginning and caches it, you know what i mean) and add it to your standard route.

    so,when you then have a request to a bad controller, it is not accepted by the normal Route. but then accepted by the catchall -> 404 route...

    0 讨论(0)
  • 2021-02-15 10:50

    I use DSO's ITCloud Contrib. None of that {controller}/{action} generic parameters. Explicit UrlRoute attributes for each action method. I like seeing the parameter constraints directly above the method.

    0 讨论(0)
提交回复
热议问题