Created
April 16, 2018 08:49
-
-
Save hartmannr76/07e474cc58d7cae0d0b6a1b2d53df65c to your computer and use it in GitHub Desktop.
.NET Core Action Filter With Controller Context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ControllerContextFilter : IAsyncActionFilter | |
{ | |
public ControllerContextFilter() { } | |
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) | |
{ | |
// Sample captures response time for controller/actions | |
var sw = new Stopwatch(); | |
sw.Start(); | |
await next(); | |
sw.Stop(); | |
var ad = context.ActionDescriptor as ControllerActionDescriptor; | |
Console.Out.WriteLine(ad?.ActionName); | |
Console.Out.WriteLine(ad?.ControllerName); | |
Console.Out.WriteLine(context?.HttpContext.Request.Method); | |
Console.Out.WriteLine(sw.ElapsedMilliseconds()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment