This repository was archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
This repository was archived by the owner on Nov 22, 2018. It is now read-only.
Static files returning 404 #65
Copy link
Copy link
Closed
Labels
Description
Here is the scenario;
- Application uses the
StaticFilesmiddleware. StaticFileshasStaticFilesOptionswhereFileProviderproperty is set to a custom provider (EmbeddedFileProvider).EmbeddedFileProvideraccepts aPhysicalFileProviderinstance which is used to check if the file physically exists. If it does,EmbeddedFileProviderjust uses thePhysicalFileProviderto return the requested file, otherwise it checks embedded resources.
// Add static files to the request pipeline.
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new EmbeddedFileProvider(new PhysicalFileProvider(hostingEnvironment.WebRootPath))
});
- Run the website using IIS/IIS Express - everything works as expected. The first request hits the homepage (
HomeController), Startup methods get called without any issues, etc. - Restart IIS/IIS Express - Do NOT request the
HomeController(/Home) but instead, make a request to a static file (that can be either a physical file or an embedded file, does not matter at all). If it is a physical file, the file returns correctly. If it is an embedded file, it returns 404 already. Either case breaks the rest of the process. - Now request the
HomeControllerwhich has references to static files using<script>tags for Javascript files and<link>tags for stylesheet files. The Home view returns correctly but none of the static files do. They return 404 instead. - Restarting the IIS/IIS Express and making the first request to a valid MVC Controller and then requesting the static files fixes the issue but everytime the first request hits a static file, the StaticFiles middleware breaks.