<
Skills Measured >> 3 Develop User Experiencesign Application Architecture >>

3.3 Design and implement MVC controllers and actions

Apply authorization attributes - AuthorizeAttribute is another filter designed specifically to enable you to wrap security around an action being taken without having to write any code as part of that action. ie. [Authorize(Roles = Admin)], [AllowAnonymous].
Filters - Filters are custom classes that provide both a declarative and programmatic means to add pre-action and post-action behavior to controller action methods.The Controller class implements each of the filter interfaces. You can implement any of the filters for a specific controller by overriding the controller's On method.

Authorization filters. - implement IAuthorizationFilter and make security decisions about whether to execute an action method, such as performing authentication or validating properties of the request. The AuthorizeAttribute class and the RequireHttpsAttribute class are examples of an authorization filter. Authorization filters run before any other filter.

Action filters - implement IActionFilter and wrap the action method execution. The IActionFilter interface declares two methods: OnActionExecuting and OnActionExecuted. OnActionExecuting runs before the action method. OnActionExecuted runs after the action method and can perform additional processing, such as providing extra data to the action method, inspecting the return value, or canceling execution of the action method. Using this ActionFilters, you can Implement Action Bahaviours

Result filters - implement IResultFilter and wrap execution of the ActionResult object. IResultFilter declares two methods: OnResultExecuting and OnResultExecuted. OnResultExecuting runs before the ActionResult object is executed. OnResultExecuted runs after the result and can perform additional processing of the result, such as modifying the HTTP response. The OutputCacheAttribute class is one example of a result filter. Using Results Filter, you can Implement Action Results

Exception filters - implement IExceptionFilter and execute if there is an unhandled exception thrown during the execution of the ASP.NET MVC pipeline. Exception filters can be used for tasks such as logging or displaying an error page. The HandleErrorAttribute class is one example of an exception filter.

How to implement and integrate customize filters

Global Filters - inherit from the GlobalFilterCollection to filter all actions within the system. Under App_Start->FilterConfig.cs, you can register your global filters.
Model Binding - implement IModelBinding to customize your own binding rules. IModelBinding Interface

Sample Question 99 | Sample Question 100 | Sample Question 101 | Case study Question 4 | Exam Question 14 | Exam Question 37 | Exam Question 143 | Exam Question 146 | Exam Question 12