为什么这个简单的owin中间件会导致403.14

时间:2015-06-17 12:40:58

标签: c# iis owin

我只是在为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中间件?)

1 个答案:

答案 0 :(得分:0)

将其添加到void Configuration(IAppBuilder app)

          app.Run(
            context =>
            {
                return context.Response.WriteAsync("More Hello, World");
            });

观察管道here

的简单说明

enter image description here

您似乎没有中间件,也没有网站。返回Task.FromResult(0)是有效的,因为现在你的中间件已经扮演了应用程序的角色,忽略了下一步并返回。

相关问题