August 2018
Intermediate to advanced
298 pages
5h 33m
English
Scenario You need to write a filter that will only allow the applied action on Sundays. How would you do that?
Aim To write a custom filter.
Steps for completion
public class SundayFilter : Attribute, IActionFilter{ public void OnActionExecuting(ActionExecutingContext context) { if (DateTime.Now.DayOfWeek != DayOfWeek.Sunday) context.Result = new ContentResult() { Content = "Sorry only on sundays!" };} public void OnActionExecuted(ActionExecutedContext context) { // do something after the action executes }}
Read now
Unlock full access