http://csharp-video-tutorials.blogspo...
Link for csharp, asp.net, ado.net, dotnet basics, mvc and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat...
In this video, we will discuss creating custom action filters in asp.net mvc.
Actions are public methods in a controller. Action filters are attributes, that can be applied either on a controller or on a controller action method, which allow us to add pre and post processing logic to the action methods. So, in simple terms an action filter allow us to execute some custom code, either, just before an action method is executed or immediately after an action method completes execution. We have discussed some of the built-in action filters in the previous sessions of this video series.
Part 70 - Authorize attribute
Part 72 - HandleError attribute
Part 73 - OutputCache attribute
Part 75 - RequireHttps attribute
Part 76 - ValidateInput attribute
Now let's discuss, creating a custom action filter. The custom action filter that we are going to build, should log the following information to a text file.
1. The name of the controller
2. The name of the action method
3. Execution time
4. If there is an exception, log the exception message and the time of the exception.
There are 4 types of filters in asp.net mvc.
1. Authorization filters - Implements IAuthorizationFilter. Examples include AuthorizeAttribute and RequireHttpsAttribute. These filters run before any other filter.
2. Action filters - Implement IActionFilter
3. Result filters - Implement IResultFilter. Examples include OutputCacheAttribute.
4. Exception filters - Implement IExceptionFilter. Examples include HandleErrorAttribute.
For detailed explanation of these attributes, please refer to the following MSDN link
http://msdn.microsoft.com/en-us/libra...
Step 1: Create an asp.net mvc 4 application using "Empty" template
Step 2: Right click on the project name in solution explorer and add "Data" folder. Add a text file to this folder and name it Data.txt
Step 3: Right click on the project name in solution explorer and add "Common" folder. Add a class file to this folder and name it "TrackExecutionTime.cs". Copy and paste the following code. Notice that our custom filter "TrackExecutionTime" inherits from ActionFilterAttribute and IExceptionFilter. ActionFilterAttribute class implements IActionFilter and IResultFilter.
Please refer to my blog, for the code associated with this video, using the link below.
Step 4: Add a HomeController. Copy and paste the following code.
public class HomeController : Controller
{ [TrackExecutionTime] public string Index() { return "Index Action Invoked"; } [TrackExecutionTime] public string Welcome() { throw new Exception("Exception ocuured"); }
}
Please Note: TrackExecutionTime class is present in MVCDemo.Common namespace.
Build the application and navigate to /Home/Index and then to /Home/Welcome. Notice that the execution times and the exception details are logged in the text file.
Please make sure to replace [ with LESSTHAN and ] with GREATERTHAN symbol.
asp.net core docker Part 77 Custom action filters in asp net mvc | |
337 Likes | 337 Dislikes |
123,856 views views | 524K followers |
Education | Upload TimePublished on 14 Aug 2013 |
Related keywords
wcf vs web api,ado.net core,sql server management studio,webkinz,webadvisor,craigslist nj,wcf one piece,asp.net core 3,ajax players,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,services angular,attributes disk clear readonly,ajax ontario,asp.net mvc tutorial,asp.net cos'è,csharp assembly,action verbs,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,action sports,asp.net zero,csharp foreach,server memes,sql date format,services online,chase,serverless architecture,server resume,wcf c#,server books,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,attribute changer,ajax deadpool,action movies on netflix,server jobs,cvs,website,mvc tutorial,costco hours,wcf service application,tutorialspoint spring,serverless,wcf soap,wcf cat,cool math games,wcf test client,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,action movies 2018,ajax parking,sql database,action movies 2019,asp.net core logging,mvconnect,cunyfirst,asp.net guida,wcf nba,csharp download,wcfi foundation,csharp online,action camera,wcf authentication,tutorials near me,action jackson,http://asp.net,server 2019,chernobyl,ado.net descargar,web of dreams,serverminer,ajax cleaner,action news,ado.net visual studio 2019,webassign,ado.net vs entity framework,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,mvc architecture,http://ado.net,asp.net core mvc,ajax soccer,server hosting,wcfi,ajax dish soap,capital one,server rack,tutorialspoint html,action news now,csharp interface,craigslist,action movies,attributeerror module 'cv2.cv2' has no attribute 'face',webroot,tutorialspoint reactjs,attribute بالعربي,ajax request,wcf dragon ball,asp.net core 2.2,tutorialspoint python 3,sql developer,webster,services transmission company sas,attributeerror module 'urllib' has no attribute 'urlopen',sql group by,asp.net core signalr,action pawn,services manager,mvc framework,ajax paving,mvc near me,tutorialspoint spring boot,mvc map,csharp online compiler,asp.net download,sql between,ado.net c# pdf,services tag dell,wcf 2019 nba,csharp switch,ado.net ventajas y desventajas,csharpstar,wcf tutorial,attribute معنى,action network,tutorialspoint,ajax meaning,attributeerror module 'pip' has no attribute 'main',csharp-video-tutorials.blogspot,tutorials dojo,attribute ترجمة,central park 5,csharp string format,ado.net c#,asp.net core github,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,server error in '/' application,attributes provided by img tag of html are source file width/height and *,services windows,asp.net core 3.0,sql injection,tutorialspoint c#,wcf ria services,calculator,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,attributes ترجمة,sqlyog,asp.net core 3 release date,sql server,server job description,tutorials by a,servicenow,webcam,mvc hours,attribute data,webmd symptom,csharp array,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,cheap flights,webcrims,asp.net core hosting,services sas,tutorialspoint java,tutorialspoint java compiler,webmd,csharp to json,college football,ado.net dataset,csharp dictionary,attributeerror 'nonetype' object has no attribute 'shape',cnn,website builder,tutorialspoint sql,attributed,asp.net web api,server side rendering,weber grills,attributeerror 'str' object has no attribute 'decode',sql server 2017,tutorialspoint spark,mvc nj,ado.net oracle,asp.net core download,csharp to vb.net,action bronson,action park,webster bank,attributes,webstaurant,tutorialsystems,ajax post,action point,services fms publish announcement,services.msc no abre,attributeerror,action news jax,ajax jersey,attributes html,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,century 21,services consultores,services consulting,mvcsd,services.msc,mvcsc,ado.net pdf,action synonym,attributes معنى,asp.net core configuration,ajax marvel,sql update,asp.net tutorial,mvc medical,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,chase online,wcf api,costco,server jobs near me,webex,action auto,sql meaning,sql tutorial,sql commands,ado.net entity framework,ajax tavern,tutorialsteacher,ajax javascript,services desk,action park nj,ajax greek,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,mvcu,asp.net core middleware,action potential,wcf web service,attributes meaning,attributed to,mvc webadvisor,web store,mvcc,webmail,mvci,mvctc,
Không có nhận xét nào:
Đăng nhận xét