Closed Eilon closed 6 years ago
From @davidfowl on August 16, 2017 8:0
Can you provide a sample that worked before that now fails? Preferably a github repository.
From @NMSLanX on August 16, 2017 9:6
Hi David: Here is the github repository. #6665.
From @davidfowl on August 16, 2017 10:14
Just for future reference so you know how to diagnose these issues. Turn logging on to a high verbosity level like trace or debug:
Change this line
To:
loggerFactory.AddConsole(LogLevel.Trace);
The log immediately shows the problem:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:64780/Index.html/
dbug: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[5]
The request path /Index.html/index.html does not match an existing file
I ran the WebApiOne project under Error. It seems like it 404s without the upgrade to 2.0, are you sure it's related?
Also, I'm not sure this has anything to do with MVC.
That trailing slash should not be there: http://localhost:64780/Index.html/
Who is sending that request?
@Tratcher it seems to happen automagically. The application is pretty vanilla. Try running it locally.
The parameter you're passing in isn't intended to be a default file name, it's intended to be a url segment. .UseDefaultFiles("/Index.html")
means you only handle default files for urls starting with "/Index.html/" (but it very helpfully will do a redirect to add that trailing slash for you). If I remove that parameter from your sample it works fine, index.html is already one of the default file names.
https://github.com/aspnet/StaticFiles/blob/5d2b1000f19dc3e892611f387b46cd519976a9f0/src/Microsoft.AspNetCore.StaticFiles/DefaultFilesMiddleware.cs#L82
That said, I'm not aware of any changes to this code for 2.0, 1.1 should have the same behavior.
While confusing, everything here is behaving as intended. Your main issue is that UseDefaultFiles and UseStaticFiles aren't using the same url path. The following works:
.UseDefaultFiles("/Index.html")
.UseStaticFiles("/Index.html")
Thanks a lot. :)
@Tratcher should we improve the docs?
Perhaps, though this is the first time I've seen someone do this in almost 5 years.
@Tratcher not many people used the katana static file server https://www.nuget.org/packages/Microsoft.Owin.StaticFiles/. Look at the downloads.
This issue was moved to aspnet/Home#2446
From @NMSLanX on August 16, 2017 7:59
Question:
1、
project: webapi core1.1 nuget: Microsoft.AspNetCore.StaticFiles file: wwwroot/Index.html ok: "http://xxxxx/Index.html" return "hello world" operation: right-click "Controller Folder" --> "Add(D)" --> "controller(T)" --> select any and "Add". error: "http://xxxxx/Index.html" return "http://xxxxx/Index.html/".
2、
project: webapi core 1.1 nuget: Microsoft.AspNetCore.StaticFiles file: wwwroot/Index.html ok: "http://xxxxx/Index.html" return "hello world" operation: update to core2.0 error: "http://xxxxx/Index.html" return "http://xxxxx/Index.html/".
Copied from original issue: aspnet/Mvc#6665