1

我正在编写一个非常基本的设置来托管一个基于 katana http Listener 的应用程序。

public class MyMiddleWare : OwinMiddleware
{
  public MyMiddleWare(OwinMiddleware next)
    : base(next) {}

  public override Task Invoke(IOwinContext context)
  {
    return new Task(() => context.Response.Write("Hello world!!"));
  }
}

public class Startup
{
  public void Configuration(IAppBuilder app)
  {
    app.Use<MyMiddleWare>();
  }
}

class Program
{
  static void Main(string[] args)
  {
    const string baseUrl = "http://localhost:5000/";

    using (var server = WebApp.Start<Startup>(new StartOptions(baseUrl)))
    {
      Console.WriteLine("Press Enter to quit.");
      Console.ReadKey();
    }
  }
}

运行这个程序时,我可以访问端口 5000,它甚至在我编写的 owinMiddleWare 中到达了一个断点。但它的响应永远不会关闭,我无法在浏览器中获得响应。

我究竟做错了什么 ?

4

1 回答 1

2

这似乎有效:

public class MyMiddleWare : OwinMiddleware
{
  public MyMiddleWare(OwinMiddleware next)
    : base(next) {}

  public override Task Invoke(IOwinContext context)
  {
    context.Response.Write("Hello world!!");
    return Next.Invoke(context);
  }
}
于 2013-09-18T20:52:00.297 回答