ASP.NET MVC Tracking User Activity (VB.NET)

In this tutorial, we are going to show how to track user activity and how to log runtime errors.We can use filter attributes to mark any action method or controller. If the attribute marks a controller, the filter applies to all action methods in that controller.

Typically, we create an action or response filter by creating an attribute class that inherits from the abstract ActionFilterAttribute class.

Some built-in action filters, such as AuthorizeAttribute and HandleErrorAttribute, inherit from the FilterAttribute class.

Other action filters, such as OutputCacheAttribute, inherit from the abstract ActionFilterAttribute class, which enables the action filter to run either before or after the action method runs.

The following tutorial shows how to create a simple action filter that logs trace messages before and after an action method is called.

So Lets Create an ASP.NET MVC internet application project

  1. Add a class TraceFilterAttribute that inherit from ActionFilterAttribute
  2. Override OnActionExecuting and OnActionExecuted methods as follow

3. Finally apply  TraceFilterAttribute to your controller action on wich we want to enable trace

Run application, so you will see that each request is tracking during action and after action. And we can retrieve action name, parameters, and entire route description.

The only thing to do now is log user activity on file or database Table

4. Now Lets log runtime errors :

Our TraceFilterAttribute must implement OnException of IExceptionFilter

Each exception can now be logged.

1 2

Thank you for feedbacks

Related tutorials :

[contact-form][contact-field label=’Nom’ type=’name’ required=’1’/][contact-field label=’Email’ type=’email’ required=’1’/][contact-field label=’Website’ type=’url’/][contact-field label=’Comment’ type=’textarea’ required=’1’/][/contact-form]


I'm a microsoft most valuable professional (MVP) .NET Architect and Technical Expert skills located in Paris (FRANCE). The purpose of this blog is mainly to post general .NET tips and tricks, Gora LEYE

Support us

BMC logoBuy me a coffee