I am having some troubles getting some very basic OWIN middleware to handle all requests to the IIS application. I am able to get the OWIN middleware to load per page request but I need it to handle requests for images, 404s, PDFs, and everything that could possible be typed into an address bar under a certain host name.
namespace HelloWorld
{
// Note: By default all requests go through this OWIN pipeline. Alternatively you can turn this off by adding an appSetting owin:AutomaticAppStartup with value “false”.
// With this turned off you can still have OWIN apps listening on specific routes by adding routes in global.asax file using MapOwinPath or MapOwinRoute extensions on RouteTable.Routes
public class Startup
{
// Invoked once at startup to configure your application.
public void Configuration(IAppBuilder app)
{
app.Map(new PathString("/*"),
(application) =>
{
app.Run(Invoke);
});
//app.Run(Invoke);
}
// Invoked once per request.
public Task Invoke(IOwinContext context)
{
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("Hello World");
}
}
}
Essentially, whether I request http://localhost/some_bogus_path_and_query.jpg or http://localhost/some_valid_request, all requests would get routed through the Invoke subroutine.
Is this possible to achieve with OWIN?
I have read threads like (How to intercept 404 using Owin middleware) but I am not having any luck. IIS Express keeps serving up 404 errors when I really need OWIN to just write Hello World in all cases, regardless of whether an asset is on disk or not.
Also, I have added runAllManagedModulesForAllRequests="true" to the web.config file and I still cannot get OWIN to fire when I am requesting images via a URL.