dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.54k stars 10.05k forks source link

Blazor Webassembly Dev Host returns 404 on URL with dot in it #45279

Open Blackclaws opened 1 year ago

Blackclaws commented 1 year ago

Is there an existing issue for this?

Describe the bug

When using a path parameter, the blazor wasm dev host returns 404 not found when the path parameter is an urlencoded url.

Example:

Create a blazor wasm project which is hosted on port 9443 and navigate to the page:

https://localhost:9443/http%3a%2f%2ftest.com%2fsomething

Expected Behavior

Blazor Wasm application loads and parses the url parameter correctly.

Steps To Reproduce

  1. dotnet new blazorwasm
  2. dotnet run
  3. Open the page shown under "Now listening on"
  4. Append http%3a%2f%2ftest.com%2fsomething as a path parameter to the url and Enter
  5. 404 is returned instead of Blazor Wasm application

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

Navigating to these urls within the blazor wasm app works as expected. Its just the initial load that isn't correctly supported by the Dev Host.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

SteveSandersonMS commented 1 year ago

I think the issue here is that you have a . character (not encoded) in the URL. That makes it try to look for a file on disk, because it looks like it has a filename extension. We use this heuristic ("if it has a filename extension, only look for files on disk") because people get confused otherwise if a request for /images/some-file-that-does-not-exist.png returns some HTML instead of a 404.

If you're using the "ASP.NET Core hosted" approach, you can control this manually by calling MapFallbackToFile based on whether you pass path:nonfile as a constraint. For the Blazor WebAssembly dev server, there is unfortunately no config option to override that.

Blackclaws commented 1 year ago

@SteveSandersonMS I get where the idea comes from. You want to directly give feedback to developers that they are missing referenced images or other files.

I think this is something that would be a nice to have if it was added to the dev host. I've now solved this problem for me personally by putting a reverse proxy in front that handles these cases in development.

It would still be nice if the dev host could be configured to not try and resolve files outside of _content, _framework and the appsettings/styles/index files.

I personally don't put anything in the main wwwroot aside from the appsettings and index.html, so all my content lives in _content anyway because its stored in class libraries. But I get that this isn't the general case.

ghost commented 12 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.