ASP.NET 4.6 WEB API not serving static files (.js, .css) IIS express visual studio

I watched over the Internet, and I still had no luck, so I ask. I have a WEB API 4.6 project, which will also contain an angularjs2 application. I installed static files to use as follows:

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); 

index.html is served when index.html tries to extract all the files (.css.js), a 404 error appears on the console. I turned on directory browsing and I see that the files are there.

0
javascript c #
source share
2 answers

I found that my code worked well, I just had to 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 can be marked as duplicate or deleted.

+1
source share

Instead of using OWIN, you can accomplish your task of serving static files from ~ / wwwroot with the web.config (URL rewrite) setting found here .

0
source share

All Articles