1

I'm just dipping into creating some custom middleware for owin, but when I run it, it's showing a 403.14 in the browser.

I created an empty WebProject, added an owin startup class like below

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);
            }
        }
    }
}

Which, when run in either IIS express (8), or IIS (7.5), it provides me with a HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory. error.

However, if I change the final line of Invoke to be return Task.FromResult(0);, then it works as expected, but I don't know if I necessarily want to be terminating the pipeline at this point (or do I, if this is the primary middleware?)

Psytronic
  • 6,043
  • 5
  • 37
  • 56

1 Answers1

0

Add this into void Configuration(IAppBuilder app)

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

Observe the simple illustration of the the pipeline here

enter image description here

It doesn't seem that you can have just middleware and no website. return Task.FromResult(0) works because now your middleware has taken the role of the app, ignoring next and returning.

Nathan Cooper
  • 6,262
  • 4
  • 36
  • 75