title: How to configure OWIN Web API 1 via IAppBuilder
body: <p><strong>TL;DR: How do I configure OWIN Web API 1 via a StartUp class or alternatively use the HttpSelfHostServer with the static files extension?</strong></p>
  
  <p>I have a working self-hosted OWIN Web API 2 project, which I'd like to downgrade to .Net 4.0 - I'd prefer not to install the .Net 4.5+ framework replacement, because of <a href="https://weblog.west-wind.com/posts/2012/mar/13/net-45-is-an-inplace-replacement-for-net-40" rel="nofollow noreferrer">unknown side-effects on a production machine</a>.</p>
  
  <p>I can't use <a href="https://stackoverflow.com/questions/38163548/iapplicationbuilder-does-not-contain-a-definition-for-usewebapi"><code>Microsoft.AspNet.WebApi.OwinSelfHost</code></a> because it's not available for .Net 4.0 and therefore I can't call the <code>IAppBuilder.useWebApi()</code> extension method for registering my configuration.</p>
  
  <p>I'm bootstraping the server now like this: <code>WebApp.Start(Of StartUp)(url:="...")</code><br>
  and the StartUp class looks like this, <strong>but I can't set the config</strong>:</p>
  
  <pre><code>Public Class StartUp
  Public Sub Configuration(app As IAppBuilder)
      ' the host should be obsolete, as it's already configured in the app context
      Dim config As New HttpSelfHostConfiguration("http://localhost:9000")
  
      ' config.MapHttpAttributeRoutes()
      config.Routes.MapHttpRoute(
          name:="DefaultApi",
          routeTemplate:="api/{controller}/{id}",
          defaults:=New With {.id = RouteParameter.Optional}
      )
  
      ' configure formatters, converters, filters ...
  
      ' app.UseWebApi(config)
  
      Dim physicalFileSystem As New PhysicalFileSystem("...\static")
      app.UseDefaultFiles(New DefaultFilesOptions With {.FileSystem = physicalFileSystem})
      app.UseStaticFiles(New StaticFileOptions With {.FileSystem = physicalFileSystem, .ServeUnknownFileTypes = True})
  End Sub
  End Class
  </code></pre>
  
  <p>If I'd use the documented <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/older-versions/self-host-a-web-api" rel="nofollow noreferrer">Web API 1 approach</a> of bootstrapping the server (see below), I don't know how to configure the static files extension:</p>
  
  <pre><code>var config = new HttpSelfHostConfiguration("http://localhost:8080");
  
  config.Routes.MapHttpRoute(
      "API Default", "api/{controller}/{id}", 
      new { id = RouteParameter.Optional });
  
  using (HttpSelfHostServer server = new HttpSelfHostServer(config)) {
      server.OpenAsync().Wait();
      Console.WriteLine("Press Enter to quit.");
      Console.ReadLine();
  }
  </code></pre>
  
  <p>Although I've checked the <a href="https://github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Http.Owin/WebApiAppBuilderExtensions.cs" rel="nofollow noreferrer">AspNetWebStack sources</a>, I think the message handling has changed between V2.1.0 and V5.0.0+ and therefore I can't apply that approach.</p>
  
  <p>I'm using the following nuget packages - which I might reduce after its working:</p>
  
  <pre><code>&lt;packages&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.SelfHost" version="4.0.30506.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.Diagnostics" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.FileSystems" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.Host.HttpListener" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.Hosting" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.SelfHost" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Owin.StaticFiles" version="2.1.0" targetFramework="net40" /&gt;
    &lt;package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" /&gt;
    &lt;package id="Newtonsoft.Json" version="4.5.6" targetFramework="net40" /&gt;
    &lt;package id="Owin" version="1.0" targetFramework="net40" /&gt;
  &lt;/packages&gt;
  </code></pre>
  
  <p><em>Btw. although I've used VB.Net in the example, feel free to use your preferred language in your answer.</em></p>