Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:26:30+00:00 2026-06-11T07:26:30+00:00

Using ASP.NET MVC 4 RTW, how do I log MVC controller actions and parameters

  • 0

Using ASP.NET MVC 4 RTW, how do I log MVC controller actions and parameters to a database? I’d like to audit user actions but don’t really want to duplicate a bunch of code inside every controller or, even worse, inside every action. Is there something i can implement globally?
I understand the EF / database side of things so this is really about MVC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:26:32+00:00Added an answer on June 11, 2026 at 7:26 am

    You should look at Custom Action Filters. Good MSDN article here http://msdn.microsoft.com/en-us/library/dd381609(v=vs.100).aspx

    The filterContext.ActionDescriptor.ActionName would give you the name of the action to log, also the filterContext.ActionDescriptor.ControllerDescriptor.ControllerName will probably help and the parameters are held in filterContext.ActionParameters

    These filters can be applied globally for all actions in the config Global.asax or in the App_Start folder under FilterConfig via.

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
        filters.Add(new LoggingFilterAttribute());
    }
    

    Example Code for Attribute

    public class LoggingFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.HttpContext.Trace.Write("(Logging Filter)Action Executing: " +
                filterContext.ActionDescriptor.ActionName);
    
            base.OnActionExecuting(filterContext);
        }
    
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Exception != null)
                filterContext.HttpContext.Trace.Write("(Logging Filter)Exception thrown");
    
            base.OnActionExecuted(filterContext);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ASP.NET MVC 3 to build an application, but i'm having a problem
I'm using ASP.NET MVC 3 with Entity Framework 4. When a user logs in,
I am using ASP.Net MVC with C# language. I would like to edit a
I am using ASP.NET-MVC and nHibernate for the first time. Great tools, but big
Using ASP.NET MVC's default view engine, you can declare a server-side comment like this:
Im using asp.net mvc c#. Based on user input I want to save the
I am using asp.net mvc and have a section where a user can upload
Using asp.net mvc, a user updates his profile. This is how my update action
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
I'm using ASP.NET MVC Preview 4 and would like to know how to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.