Is it possible to use ExceptionFilterAttribute in a project the was created with MVC2 and upgraded to MVC4? It is not a Web API project, and I cannot seem to get the exception to catch using the ExceptionFilterAttribute. Is there any way to make this happen or am I better off just sticking to inheriting from ActionFilterAttribute and implementing IExceptionFilter. This is for an API section within our MVC project

有帮助吗?

解决方案

MVC attributes and Web API attributes are not compatible.

MVC ones are of System.Web.Mvc.Filter type [1], while Web API are of System.Web.Http.Filters.Filter type [2] - so you need to make sure you get your base class correct before trying to apply the attribute to Web API.

[1] - http://msdn.microsoft.com/en-us/library/system.web.mvc.filter(v=vs.98).aspx

[2] - http://msdn.microsoft.com/en-us/library/system.web.http.filters.filter(v=vs.108).aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top