C#/.NET 分布式专题(SOA【面向服务】WebApi行为过滤处理方式)

行为异常过滤

public class CustomActionFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(HttpActionContext actionContext)
    {
        Console.WriteLine("1234567");
    }

    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
        Console.WriteLine("2345678");
        actionExecutedContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
    }
}

使用方法如前面说的异常处理,用法一样都是特性用法

发布了143 篇原创文章 · 获赞 117 · 访问量 4236

猜你喜欢

转载自blog.csdn.net/weixin_41181778/article/details/103863450