Asp.Net核心:从另一个中间件

时间:2017-08-02 19:30:38

标签: c# asp.net-core

我是C#中异步模式的新手,并尝试使用Asp.Net核心。

我希望在从Middleware_NotifyWPF中的控制器操作收到响应后调用方法InformUI()。 怎么做? [类似于Middleware_NotifyWPF的request.on(' end')事件处理程序。]

Startup.cs:

  public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.Middleware_NotifyWPF();
            app.UseMvc();
        }

中间件1:

    public class Middleware_NotifyWPF
        {
            private readonly RequestDelegate _next;
            private static Logger _logger = LogManager.GetCurrentClassLogger();

            public Middleware_NotifyWPF(RequestDelegate next)
            {
                _next = next;
            }

            public Task Invoke(HttpContext httpContext)
            {
                return _next(httpContext);


                InformUI(httpContext.Request, httpContext.Response); //Unreachable code
            }
}

控制器类|行动方法

        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

1 个答案:

答案 0 :(得分:3)

您需要等待任务才能在

之后到达代码
public async Task Invoke(HttpContext httpContext)
{
    await _next(httpContext);

    InformUI(httpContext.Request, httpContext.Response); 
}