I want to handle uncaught exceptions in my ASP.NET MVC 3 application, so that I may communicate the error to the user via the application's error view. How do I intercept uncaught exceptions? I'd like to be able to do this globally, not for each controller (although I wouldn't mind knowing how to do this as well).
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- Entity Framework throws exception - Network Relate
- parameters in routing do not work MVC 3
- Slow loading first page - ASP.NET MVC
- There is no ViewData item with the key 'taskTy
相关文章
- “Dynamic operations can only be performed in homog
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
- Cannot implicitly convert Web.Http.Results.JsonRes
in order to make this work I followed the following blog post and then make the following addition to both Web.config files (the root one and the one in the Views folder) inside the
<system.web>
node:Hope it helps...
Global Error Handling
Add in web.config
Error will be displayed on Error.cshtml which is resides in shared folder
For completeness sake, there is also the Application_Error handler in Global.asax.
you can use HandleErrorAttribute filters,
basically you can have this on top of a base controller and define the UnhandledError.cshtml in the Shared views folder.
And if you want to log the unhandled errors before you show the error message then you can extend the HandleErrorAttribute class and put the logic to do the logging inside the OnException method.
You can set up a global error filter in
Global.asax
The above sets up a default error handler which directs all exceptions to the standard error View. The error view is typed to a
System.Web.Mvc.HandleErrorInfo
model object which exposes the exception details.You also need to turn on custom errors in the web.config to see this on your local machine.
You can also define multiple filters for specific error types:
Note that
HandleErrorAttribute
will only handle errors that happen inside of the MVC pipeline (i.e. 500 errors).