Asp.Net MVC Exploring Controllers in depth Part 5 – Bestdotnettraining

Asp.Net MVC Exploring Controllers in-depth Part 5 – Bestdotnettraining

Filter Types

    Description: Asp.Net MVC Exploring Controllers in-depth      Part 5

ASP.NET MVC supports the following types of filters:

1.        Authorization Filter:

  • Class Implementing IAuthorizationFilter
  • Eg: AuthorizeAttribute and RequireHttpsAttribute
  • Can override the OnAuthorization method

2.        Action Filter:

  • Class Implementing IActionFilter
  • Eg: ActionFilterAttribute – Used for writing Custom Attributes
  • Can override OnActionExecuting and OnActionExecuted

3.        Result Filter:

  • Class Implementing IResultFilter
  • Eg:
  • ActionFilterAttribute implements both IResultFilter and IActionFilter.
  • Can override OnResultExecuting and OnResultExecuted

4.        Exception Filter:

  • Class Implementing IExceptionFilter
  • Eg: HandleErrorAttribute

Continue reading “Asp.Net MVC Exploring Controllers in depth Part 5 – Bestdotnettraining”

Please follow and like us:
0

Asp.Net MVC Exploring Controllers in depth Part 4. Best Dot Net Training

 Asp.Net MVC Exploring Controllers in-depth Part 4. Best Dot Net Training

MVC – Action Filters

Action filters will apply pre or post Processing logic to a controller action and its result. Action filters are the component we want to use to apply cross-cutting logic to our application i.e. the logic that we must execute across multiple controller actions but we do not want to duplicate the logic inside of the individual controller.

Name Description
OutputCache Cache the output of an Action method.
Authorize Restrict an action or controller to authorize user or role.
ValidateInput Turn on/off the request validation.
ValidateAntiForgeryToken Helps prevent cross site request forgeries.
HandleError Can specify a view to render in the event of an unhandled exception.

                OutputCache: tells the runtime that it allows to cache the final output of the action and use the cached result to serve the future request.

[OutputCache(Duration=10, VaryByParam=”t1″)]

               Authorize: Authorize attribute to allow us to ensure that the user is login before action/controller allow to process the request. Continue reading “Asp.Net MVC Exploring Controllers in depth Part 4. Best Dot Net Training”

Please follow and like us:
0

Asp.Net MVC Exploring Controllers in-depth Part 3

Asp.Net MVC Exploring Controllers in-depth Part 3 Action Selectors

When the MVC Framework is selecting one of the controller public methods to invoke as an action, it will use any

action selector attribute that might be present to define the correct action to invoke.

  1. ActionName
  2. AcceptVerbs
    • HttpPost
    • HttpGet

ActionName: When we apply this to a controller action it will specify the action name for that method.

For the Index method, we have bellow we no longer reach this method as action name “Index”. We have to reach this method as “Start”. (http://localhost:123/Home/Start) Continue reading “Asp.Net MVC Exploring Controllers in-depth Part 3”

Please follow and like us:
0

Asp.Net MVC Exploring Controllers in depth Part 2.Best Dot Net Courses

Asp.Net MVC Exploring Controllers in-depth Part 2.Best Dot Net Courses

 

Learn MVC to build web apps using the Model View Controller pattern. ASP.NET MVC 5 provides this functionality to the ASP.NET framework as an alternative to the Web Forms pattern

Passing data from Controller to View

ViewBag vs. ViewData vs. TempData

All three are properties

    • ViewData is a dictionary object that you put data into, which then becomes available to the ViewData is a derivative of the ViewDataDictionary class, so you can access by the familiar “key/value” syntax.
    • ViewBag object is a wrapper around the ViewData object that allows you to create dynamic properties for the ViewBag.
    • Both the ViewData and ViewBag objects are great for accessing extra data (i.e., outside the data model), between the controller
    • Asp.Net MVC Exploring Controllers in-depth Part 2.Best Dot Net Courses

Continue reading “Asp.Net MVC Exploring Controllers in depth Part 2.Best Dot Net Courses”

Please follow and like us:
0