Closed daveaglick closed 3 years ago
I'm having trouble replicating this locally, so might be something about the way GitHub Codespaces forwards ports.
It appears the 301 is being issued by Kestrel - I can now reproduce (I always could, just didn't realize it). When a URL like /foo/bar
is requested and there's no /bar
file, a 301 is issued to /foo/bar/
and then the default file logic kicks in. The trick will be to figure out what's issuing the 301 and have it use the current host header instead of localhost
.
Possibly related: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1
I imagine this doesn't happen when testing with an alternate DNS name locally because the alternate DNS is actually set by the client in the request. When issued through a proxy, the proxy issues the request for localhost
and the server never sees the original host header.
I'll try adding UseForwardedHeaders()
and we'll see if that resolves it.
It appears to be caused by UseDefaultFiles
:
Here's the flow:
UseDefaultFiles
triggers a redirect using the current host headerUseDefaultFiles
sees is localhost
localhost
in the clientConfirmed working now
For example when using GitHub Codespaces to forward a port, the host name of the proxy is not
localhost
. When a URL that relies on default filenames (I.e. an/foo/index.html
is requested as/foo
) the preview server redirects/rewrites the URL tohttps://localhost/foo
. This doesn’t appear to be happening with other middleware like default extensions (probably because the default file name support is built-in to Kestrel while the other stuff is custom).