Wednesday 10 August 2016

Exception Filter in ASP.NET MVC

Posted by : Manav Pandya
Exception Filter in ASP.NET MVC

How to Define Exception Filter in ASP.NET MVC ?


Before you refer this post gone through my previous article as :


Exception filters implement IExceptionFilter and execute if there is an unhandled exception thrown. ASP.Net MVC provides HandleErrorAttribute class as an exception filter .


Authorize filter attribute implements the IAuthorizationFilter interface. The definition of this interface is given below :-

Code :



public interface IAuthorizationFilter
{

void OnAuthorization(AuthorizationContext filterContext);

}

Exception filters can be used for logging or displaying an error page. We may also define our custom exception filter.



MVC , .NET CORE 1.0  ,  Razor  , CRUD , AJAX , C#