Controller.OnActionExecuting Method (System.Web.Mvc)

Switch View :
ScriptFree
.NET Framework Class Library
Controller.OnActionExecuting Method

Called before the action method is invoked.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)
Syntax

Visual Basic (Declaration)
Protected Overridable Sub OnActionExecuting ( _
	filterContext As ActionExecutingContext _
)
Visual Basic (Usage)
Dim filterContext As ActionExecutingContext

Me.OnActionExecuting(filterContext)
C#
protected virtual void OnActionExecuting(
	ActionExecutingContext filterContext
)
Visual C++
protected:
virtual void OnActionExecuting(
	ActionExecutingContext^ filterContext
)
JScript
protected function OnActionExecuting(
	filterContext : ActionExecutingContext
)

Parameters

filterContext
Type: System.Web.Mvc.ActionExecutingContext
Information about the current request and action.
Remarks

If this method is overridden in a derived Controller class, it will be called for every action method in the class. For more flexibility, derive a class from ActionFilterAttribute and override this method in the derived ActionFilterAttribute class.

Examples

The following example shows how to write trace information for the action name before the action method runs.

C#
protected override void OnActionExecuting(ActionExecutingContext ctx) {
    base.OnActionExecuting(ctx);
    ctx.HttpContext.Trace.Write("Log: OnActionExecuting",
         "Calling " +
         ctx.ActionDescriptor.ActionName);
}
Visual Basic
Protected Overloads Overrides Sub OnActionExecuting(ByVal ctx As ActionExecutingContext) 
    MyBase.OnActionExecuting(ctx) 
    ctx.HttpContext.Trace.Write("Log: OnActionExecuting", "Calling " & ctx.ActionDescriptor.ActionName) 
End Sub
See Also

Reference