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 Web App Template Global Interactivity location causes Not Found issue when navigate to the page/component in Server project. #58944

Open DillionVVV opened 1 week ago

DillionVVV commented 1 week ago

Is there an existing issue for this?

Describe the bug

Firstly, I understand the basics of Blazor render mode. When we use "Blazor Web App" template create application, it will generate two projects: main project (server) and .Client project (client), then we need to put the server-side rendering component in the server project and put the client-side rendering component in the .client project.

Recently, I found that when use "Blazor Web App" template create application, in the Additional Information window,

Image

If we select the select the "Auto (Server and WebAssembly)" Interactive render mode and "Global" Interactivity location, then in the Blazor Server project add a Test component (set the rendermode as InteractiveServer), after running the application and navigate to the Test page, firstly it will show the Test page content, after some seconds (2 or 3 seconds), it will auto display "Not Found" in the page.

I have also report this issue in this thread: https://github.com/dotnet/aspnetcore/issues/58480

But this issue still not fixed in .NET 9.

Expected Behavior

After redirecting to test page, it should stay on the test page instead of showing "Not Found".

Steps To Reproduce

  1. Create a new Blazor application using the Blazor Web App Template. In the Additional Information window, select the "Auto (Server and WebAssembly)" Interactive render mode and "Global" Interactivity location: Image

  2. In the Server project, add a Testpage component in the Components/Pages folder, like this:

    Image

  3. Running the application, navigate to the Test page, firstly the output as below:

    Image

    then, a few seconds later, it will auto display "Not Found", like this:

    Image

Exceptions (if any)

No response

.NET Version

.NET 8 and .NET 9

Anything else?

I check it using the following version of VS 2022, both of them show the same issue:

Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.11.5

Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.12.0

Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.12.0 Preview 3.0

Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.13.0 Preview 1.0

Besides, I also compare it with my old Blazor Web Application, it seems that this issue relate the Routes.razor component and the Layout content, in previous projects, these files are in the Server project, but now they are in the Client project.

Image

And when use "Blazor Web App" template create application, in the Additional Information window, if we select the "Per page/Component" Interactivity location, these files are also in the server project.

So this might be a bug about the "Blazor Web App" template and Interactivity location. Please help to check and fix it.

javiercn commented 1 week ago

@DillionVVV thanks for contacting us.

This behavior is by design. On global interactivity, all the pages should be on the client project. Otherwise, they won't be in any assembly downloaded to the browser, not registered on the client router and that will result in the not found that you are seeing.

dotnet-policy-service[bot] commented 1 week ago

Hi @DillionVVV. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

guardrex commented 4 days ago

BTW @danroth27 ... This is what I was covering that you requested I pull on https://github.com/dotnet/AspNetCore.Docs/issues/34041. If this is a supported scenario, then I recommend we bring that coverage back, as it's hard to guess.