Asp.Net MVC Exploring Controllers in-depth Part 8 – Bestdotnettraining
Cancelling Filter Execution
- You can cancel filter execution in the OnActionExecuting methods by setting the Result property to a non-null value.
- Any pending OnActionExecuted and OnActionExecuting filters will not be invoked
- Invoker will not call the OnActionExecuted method for the cancelled filter or for pending
- The OnActionExecuted filter for previously run filters will
- All of the OnResultExecuting and OnResultExecuted filters will
- You can cancel filter execution in the OnResultExecuting methods by setting the Cancel property.
- Any pending OnResultExecuted and OnResultExecuting are cancelled and blank o/p is rendered to the browser.
- The OnResultExecuted filter for previously run filters will run.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class Log2Attribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { //filterContext.Result = new EmptyResult(); Trace("On Action Executing", filterContext.RouteData); } { Trace("On Action Executed", filterContext.RouteData); } { filterContext.Cancel = true; } { } string str = string.Format("2 - Method Name={0}, Controller Name={1}, Action={2}", methodName, colName, actionName); System.Diagnostics.Trace.WriteLine(str); HttpContext.Current.Response.Write("<br>" + str + "<br>"); } } |
Vist for MVC online Training for Beginners
Please follow and like us: