ASP.Net Action Filters
w3hello.com logo
ASP.NET Basics
ASP.Net Introduction
ASP.NET - Introduction
ASP.NET - Environment Setup
ASP.NET - Basic Controls
ASP.Net Button
ASP.Net RadioButton
ASP.Net Textbox
ASP.Net Label
ASP.NET - Client Side
ASP.NET - Server Side
ASP.NET - Ad Rotator
ASP.Net Hyperlink
ASP.NET - Calendars
ASP.NET - Life Cycle
ASP.NET - Debugging
ASP.Net Session
ASP.Net LinkButton
ASP.Net DropDownList
ASP.NET - Data Binding
ASP.Net Calender
ASP.Net Checkbox
ASP.NET - Multi Threading
ASP.Net Tutorial
ASP.NET - File Uploading
ASP.Net Upload Multiple Files
ASP.Net Cookie
ASP.NET - Quick Guide
ASP.NET - Data Caching
ASP.NET Useful Resources
ASP.NET - Multi Views
ASP.NET - Panel Controls
ASP.NET - Deployment
ASP.Net DataGrid
ASP.Net WebForm User Registration
ASP.NET - Security
ASP.NET - LINQ
ASP.Net Action Filters
ASP.NET - Error Handling
ASP.Net Fileuplaod
ASP.NET - Data Sources
ASP.NET - Validators
ASP.NET - Ajax Control
ASP.NET Tutorial in PDF
ASP.NET - HTML Server
ASP.NET - Directives
ASP.Net DataList
ASP.NET - Custom Controls
ASP.NET - Configuration
ASP.Net WebForm Validation Summary
ASP.NET - Server Controls
ASP.NET - Managing State
ASP.NET - Event Handling
Learn ASP.Net Tutorial
ASP.Net Server Controls
ASP.NET - Database Access
ASP.NET - Web Services
ASP.NET - Personalization
ASP.Net Life Cycle
Discuss ASP.NET
ASP.Net Download File
ASP.NET Basics
Previous : ASP.NET - LINQ Next : ASP.NET - Error Handling

ASP.Net Action Filters


The MVC framework provides the filter attribute so that we can filter the user requests. We can apply it to an individual action or an entire controller. It completely modified the way in which an action is called.

The ASP.NET MVC Framework provides the following action filters.

OutputCache: it makes controller's action output cacheable for the specified time.

HandleError: It is used to handle error raised when a controller action executes.

Authorize: It allows only authorize user to access resources.

OutputCache Example

Here, we are implementing OutputCache that will cache the action method output for the specified time. The action code is given below:

// MusicStoreController.cs

It renders an index file that has the following code.

// index.cshtml

Output:

It produces the following output and cache that for 10 seconds. It will not change before 10 seconds even we refresh the web page again and again.

ASP Action filters
1

Authorize Example

Now, we are applying authorize attribute to the action method, the code is given below.

// MusicStoreController.cs

Output:

This attribute will restrict unauthorized user access. The application redirects to the login page for authentication.

ASP Action filters
2
Previous : ASP.NET - LINQ Next : ASP.NET - Error Handling
© Copyright 2018 W3Hello Publishing Limited. All rights reserved.
Contact us | Sitemap