Tutorial by Examples

public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Log("OnActionExecuting", filterContext.RouteData); } public override void OnActionExecuted(ActionExecute...
Usually authentication&authorization processes are performed by built-in cookie and token supports in .net MVC. But if you decide to do it yourself with Session you can use below logic for both page requests and ajax requests. public class SessionControl : ActionFilterAttribute { public o...
You can place action filters at three possible levels: Global Controller Action Placing a filter globally means it will execute on requests to any route. Placing one on a controller makes it execute on requests to any action in that controller. Placing one on an action means it runs with the...
This attribute handles all unhandled exceptions in the code, (this is mostly for Ajax Requests - that deal with JSON - but can be extended) public class ExceptionHandlerAttribute : HandleErrorAttribute { /// <summary> /// Overriden method to handle exception /// </summary...

Page 1 of 1