开发者

MVC HandleError attribute not working on Controller

开发者 https://www.devze.com 2023-01-10 02:46 出处:网络
I am experimenting with the relationship between Elmah and MVC\'s plumbed in exception handling, and am surprised at the outcome of the following code.This is a brand new, straight from project templa

I am experimenting with the relationship between Elmah and MVC's plumbed in exception handling, and am surprised at the outcome of the following code. This is a brand new, straight from project template MVC application, and I have only added Elmah modules and handlers to the web.config. And of the course the 'throw':

[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome to ASP.NET 开发者_如何学GoMVC!";
        throw new Exception("Just for you Elmah!");
        return View();
    }

Break when error is thrown is set to off, yet the debugger still breaks. When I continue I get a YSOD, and an Elmah error log, but it seems HandleError is doing nothing.

JUST IN I didn't think I had to have custom errors turned on, as I thought that was only for 'my' unhandled errors. I guess MVC is just as much a client of that service as I am.


So to start ASP.net MVC [HandleError] not catching exceptions and then onto the logging How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?


Check HandleErrorAttribute is added to the GlobalFiltersCollection in the Global.asax.cs

public static void RegisterGlobalFilters(GlobalFiltersCollection filters)
{
  filters.Add(new HandleErrorAttribute());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消