【发布时间】:2016-03-25 19:04:15
【问题描述】:
我正在学习 Scott Allen 关于 Pluralsight 的 MVC 5 基础课程
以下代码应该可以工作,但是当我浏览到 localhost:8080 时,我得到一个空白页
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Owin.Hosting;
using Owin;
namespace ConsoleApplication1
{
using AppFunc = Func<IDictionary<string, object>, Task>;
class Program
{
static void Main(string[] args)
{
string uri = "http://localhost:8080";
using (WebApp.Start<Startup>(uri)) // Katana Please start, using the configuration from the Startup class and listening on the port given by the uri
{
Console.WriteLine("Started!");
Console.ReadKey();
Console.WriteLine("Stopping!");
}
}
}
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use<HelloWorldComponent>();
}
}
public class HelloWorldComponent
{
AppFunc _next;
public HelloWorldComponent(AppFunc next)
{
_next = next;
}
// Katana uses reflection to find this Invoke function that matches the AppFunc signature
public Task Invoke(IDictionary<string, object> environment)
{
var response = environment["owin.ResonseBody"] as Stream;
using (var writer = new StreamWriter(response))
{
return writer.WriteAsync("Hello");
}
}
}
}
如何让它工作?
【问题讨论】:
-
我看到 Invoke 方法实际上与 AppFunc 签名不匹配,因为它不包含 Task
-
IAppBuilder 在 Owin 中已被弃用...但 Katana 是基于它构建的。 jamesmckay.net/2014/08/…
标签: reflection owin katana