【问题标题】:Why does this simple owin middleware cause a 403.14为什么这个简单的 owin 中间件会导致 403.14
【发布时间】: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 中间件?)

【问题讨论】:

标签: c# iis owin


【解决方案1】:

将此添加到void Configuration(IAppBuilder app)

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

观察流水线的简单图解here

您似乎不能只有中间件而没有网站。 return Task.FromResult(0) 有效,因为现在您的中间件已扮演应用程序的角色,忽略下一个并返回。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-23
    • 2013-12-30
    相关资源
    最近更新 更多