0
votes

I am very new to OWIN and trying to understand how OWIN mapping extension will work. I created an Empty ASP.Net project and referenced Owin, Microsoft.Owin, Microsoft.Owin.Host.SystemWeb packages.

I created a middleware class something like bello.

public class TempMiddleware : OwinMiddleware
{
    public TempMiddleware(OwinMiddleware next) 
        : base(next)
    {
    }

    public override Task Invoke(IOwinContext context)
    {
        return context.Response.WriteAsync("Response from Temp Middleware");
    }
}

Here is my OWIN startup class.

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Map("/temp", config => config.Use<TempMiddleware>());
    }
}

I configured the portal project something like this.

enter image description here

When I run the project from VS2017, it returns HTTP Error 403.14 - Forbidden page.

Actually my expectation is, it should print "Response from Temp Middleware" message on the browser.

Any issues in my code ?

Thanks

1

1 Answers

0
votes

Map() is used for branching the pipeline. In the delegate, the second parameter of the Map() method, you rather need to Run a middleware.

This is how your configuration code should be:

public void Configuration(IAppBuilder app)
{
    app.Map("/temp", config => config.Run(async context => 
    {
        await context.Response.WriteAsync("Response from Temp Middleware");
    }));
}