MVC Core里的特殊路由 -- IAlwaysRunResultFilter

用于无论什么时候都要执行的Action标记,应用场景--记录谁尝试访问过当前网址,无论他是否成功访问

代码:

public class CustomResultCancelBeforeFilterAttribute : Attribute, IFilterMetadata, IOrderedFilter, IResultFilter, IAlwaysRunResultFilter
{
public int Order { get; set; }

public void OnResultExecuted(ResultExecutedContext context)
{
Console.WriteLine($"This {nameof(CustomResultCancelBeforeFilterAttribute)} OnResultExecuted {this.Order}");
}

public void OnResultExecuting(ResultExecutingContext context)
{
Console.WriteLine($"This {nameof(CustomResultCancelBeforeFilterAttribute)} OnResultExecuting{this.Order}");
}
}

posted @ 2020-05-12 09:32  FiberHomer  阅读(281)  评论(0编辑  收藏  举报