为了进行诊断,在OData Controller中要为这两个事件覆盖的等效动作是什么:
我只能找到一个:
public class BaseODataController : ODataController
{
public override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
{
return base.ExecuteAsync(controllerContext, cancellationToken);
}
}
最重要的是,一旦我们从操作返回控件(在生命周期事件中),我们就可以测量诊断信息,例如,应用查询过滤器:方法执行所花费的时间。
答案 0 :(得分:2)
首先,您需要定义一个过滤器:
public class SampleActionFilter : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
// do something before the action executes
}
public void OnActionExecuted(ActionExecutedContext context)
{
// do something after the action executes
}
}
然后将属性应用于控制器中的操作:
[Route("api/[controller]")]
[ApiController]
public class FooController : ODataController
{
[SampleActionFilter]
[HttpGet("SomeResource")]
public IActionResult SomeResource()
{
return Content("Successful access to resource - header should be set.");
}
}
您可以检查以下链接:https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-2.1
让我知道是否有用。