当我在配置中使用 Mvc() 时,如何在聊天机器人中加入中间件。我需要为它创建一个扩展方法吗?



我想在我的聊天机器人中添加两个中间Wares,一个用于处理一些自定义参数,另一个用于logger。在我的startup.cs,配置方法中,我使用app.usemvc((代替app.usebotframework((。当我使用MVC时,我该如何参与中间。

  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }
        app.UseDefaultFiles();
        app.UseStaticFiles();
        //app.UseHttpsRedirection();
        //app.UseBotFramework();
        app.UseMvc();
    }

blockquote

我们可以在控制器中添加中间件,示例代码如下。

[HttpPost]
public async Task PostAsync()
{
  // Delegate the processing of the HTTP POST to the adapter.
  // The adapter will invoke the bot.
  ((BotAdapter)_adapter).Use(new EndpointMiddleware());
  await _adapter.ProcessAsync(Request, Response, _bot);
}

不确定这是正确的方法,但是它正常工作。

最新更新