Posts

Showing posts from March, 2024

Handle Exception Using Exception Filter ASP.NET MVC 5

Image
 using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace WebApplication31.Filter  public class NitishException : FilterAttribute, IExceptionFilter   public void OnException(ExceptionContext filterContext) filterContext.Result = new ViewResult() { ViewName = "Error" }; } }

ActionFilterAttribute in MVC 5

The ActionFilterAttribute is the base class for all the attribute filters. It provides the following methods to execute a specific logic after and before controller action's execution: 1. OnActionExecuting: Just before the action method is called. 2. OnActionExecuted: After the action method is called and before the result is executed (before view render). 3. OnResultExecuting: Just before the result is executed (before view render). 4. OnResultExecuted: After the result is executed (after the view is rendered).