Search code examples
asp.netowinkatanaself-hosting

How to set default static web page for Katana/Owin self hosted app?


I've set up a web site using an Owin self hosted console app. I'm serving static files with no problem, the 'root' of the static part of the site works properly, and the web API routes work fine also.

If I browse to:

http://localhost/index.html

it presents everything like I expect. But I have not figured out how to set it so that browsing to:

http://localhost

presents index.html (as the default view). This Just Works under an IIS-style site. How do I make it work with Owin self host?


Solution

  • I do it this way:

    var physicalFileSystem = new PhysicalFileSystem(webPath);
    var options = new FileServerOptions
                              {
                                  EnableDefaultFiles = true,
                                  FileSystem = physicalFileSystem
                              };
            options.StaticFileOptions.FileSystem = physicalFileSystem;
            options.StaticFileOptions.ServeUnknownFileTypes = true;
            options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
            appBuilder.UseFileServer(options);