How to serve index.html with web api selfhosted with OWIN

后端 未结 1 1792
傲寒
傲寒 2021-01-30 17:17

Should be an easy question, just can\'t find the answer.

I have an SPA (AngularJS) with web api which is self hosted with Owin. I use Nancy to serve the page, but I woul

1条回答
  •  情话喂你
    2021-01-30 17:58

    Move your Index.html to the root of your project. Then install-package Microsoft.Owin.StaticFiles in Package Manager Console and add the code below:

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
    
            const string rootFolder = ".";
            var fileSystem=new PhysicalFileSystem(rootFolder);
            var options = new FileServerOptions
                          {
                              EnableDefaultFiles = true,
                              FileSystem = fileSystem
                           };
    
            app.UseFileServer(options);
    
        }
    }
    

    This will serve up your Index.html by default.

    You can checkout Scott Allen's blog for more reading:

    http://odetocode.com/blogs/scott/archive/2014/02/10/building-a-simple-file-server-with-owin-and-katana.aspx

    0 讨论(0)
提交回复
热议问题