ASP.NET 4.6 WEB API,不提供静态文件(.js,.css)IIS Express Visual Studio

ASP.NET 4.6 WEB API,不提供静态文件(.js,.css)IIS Express Visual Studio

问题描述:

我一直在网上浏览,但依旧没有运气,所以我为什么要问.我有一个WEB API 4.6项目,该项目也将是angularjs2应用程序的所在地,我已经设置为使用像这样的静态文件:

I have been looking over the web and still no luck, hence why I am asking. I have a WEB API 4.6 project that will also be home to an angularjs2 application, I have set up to use static files like this:

 var physicalFileSystem = new PhysicalFileSystem(@".\wwwroot\");
        var options = new FileServerOptions
        {
            EnableDefaultFiles = true,
            FileSystem = physicalFileSystem,
        };
        var contentTypes = new FileExtensionContentTypeProvider();

        options.StaticFileOptions.FileSystem = physicalFileSystem;
        options.StaticFileOptions.ServeUnknownFileTypes = true;
        options.StaticFileOptions.ContentTypeProvider = contentTypes;
        options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
        options.EnableDirectoryBrowsing = true;
        app.UseFileServer(options);

当索引文件尝试获取所有文件(.css.js)时,在控制台中显示404错误,从而提供了

index.html.我已启用目录浏览,并且看到文件在那里.

index.html is served, when index.html tries to fetch all the files(.css.js) a 404 error shows up in the console. I have enabled directory browsing and I see that the files are there.

我发现我的代码运行良好,我只需要将以下代码添加到我的web.config文件中即可.

I found that my code works well, I had to just add the following code to my web.config file.

<system.webServer>
<handlers>
  <remove name="StaticFile"/>
  <add name="Owin" verb="" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb"/>
</handlers>

找到了答案

found the answer here. I believe this could be marked as a duplicate or deleted.