【发布时间】:2015-06-18 16:19:41
【问题描述】:
我只是想为 owin 创建一些自定义中间件,但是当我运行它时,它在浏览器中显示 403.14。
我创建了一个空的 WebProject,添加了一个 owin 启动类,如下所示
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(OwinTest.Startup))]
namespace OwinTest {
public class Startup {
public void Configuration(IAppBuilder app) {
app.Use<MySimpleMiddleware>();
}
class MySimpleMiddleware : OwinMiddleware {
public MySimpleMiddleware(OwinMiddleware next) : base(next) { }
public override Task Invoke(IOwinContext context) {
context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
context.Response.ContentType = "text/plain";
context.Response.Write("Hello, world.");
return base.Next.Invoke(context);
}
}
}
}
当在 IIS express (8) 或 IIS (7.5) 中运行时,它会为我提供 HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory. 错误。
但是,如果我将 Invoke 的最后一行更改为 return Task.FromResult(0);,那么它会按预期工作,但我不知道我是否一定要终止管道这一点(或者我,如果这是primary 中间件?)
【问题讨论】:
-
我发现这篇 SO 帖子很有用:stackoverflow.com/a/20204884/2638872