dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.62k stars 25.31k forks source link

Add Blazor migration guidance on service/endpoint configuration #30843

Closed shrayasr closed 2 months ago

shrayasr commented 1 year ago

Description

Allow me to set some context first. We are heavily invested in Blazor but we had to take a pause because of the incomplete auth story. I tweeted this out and @danroth27 kindly responded asking me to check if it was fixed in NET8. And it has been! So we're back on the Blazor bandwagon now.

However while we were upgrading, we saw the following suggestion

- app.MapBlazorHub();
+ app.MapRazorComponents<App>()
+   .AddInteractiveServerRenderMode()

And we're kind of stuck here since our previous call to MapBlazorHub looked like this:

endpoints.MapBlazorHub(config =>
{
    config.CloseOnAuthenticationExpiration = true;
});

And we're unable to find out where we should be moving the CloseOnAuthenticationExpiration call to?

Is this something that you're able to help us with?

Cheers and thanks for all the great work!

Page URL

https://learn.microsoft.com/en-us/aspnet/core/migration/70-80?view=aspnetcore-7.0&tabs=visual-studio

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/migration/70-80.md

Document ID

534ab561-09c5-c33b-4394-0effba34d666

Article author

Rick-Anderson

guardrex commented 1 year ago

Thanks for moving it over to this issue.

Yes! I totally agree ... and I ran into this exact scenario working on the reference docs. IIRC, I was working on updating the SignalR docs where hub config was shifting over based on the new extension methods. I couldn't find some optons but came to learn that they would appear in the next preview. Indeed, they arrived, and you can see the final result in this section ...

https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-8.0#server-side-circuit-handler-options

WRT to the auth question that you're asking, I might need to ping Jeremy to ask (or Steven Halter), as they're handling a certain amount of the auth updates this time around. However, I might be able to sort it out on my own.

I'm wrapping up a Blazor Forms article PR this morning, and I'll see if I can resolve this issue today. My plan in the non-auth cases is to cross-link to the new guidance (e.g., link to that SignalR options section from the Migration topic for SignalR hub config). We can't do that yet for auth options or setup because auth content hasn't been produced yet. What I'll do for anything I discover today on auth is call it out in the topic with examples there for the time being.

I'll get back to you later today.

guardrex commented 1 year ago

@shrayasr ... I'm really happy that you opened this because I'm finding several sneaky bits 😈 that are trying to get past me for migration coverage. I'll have a PR up soon, but I wanted to jump in here and ask you to try this for that option ...

app.MapBlazorHub(options => options.CloseOnAuthenticationExpiration = true);

Place it after your call to app.MapRazorComponents.

guardrex commented 1 year ago

~BTW ... I'm saying that I know it will work. That's just to get the ball rolling with what looks like might work πŸ€žπŸ€:smile:. I'm going to ask the PU to review my PR, which will include the MapBlazorHub guidance that I'm adding along with other sneaky bits that I found to document. We'll get some feedback on the PR shortly after it goes up, and I'll ping you on the PR so that you can see what they say on review.~

No ... actually ... truly ... I think we'll be fine with the new section. I can't really hold up that doc, given that other doc authors might need to get in there at any point. I'll ask offline for the PU to put an πŸ‘οΈ on that after it goes in.

guardrex commented 1 year ago

... and BTW @shrayasr ... It's not an 8.0 thing, nor is it really "migration" guidance in the sense of upgrading a Blazor app. It's more a point of "migration" from other app types to Blazor. We just never had the options covered for MapBlazorHub, which is definitely an oversight. I'm taking care of that now in the Fundamentals > SignalR doc. It won't appear in migration guidance, but I will ask on review after merging so as not to hold up the migration article for other updates if what I'm placing is reasonable. The migration guidance is receiving a nice update based on your ask for general options that will have a new call structure for Blazor Web Apps.

shrayasr commented 1 year ago

Hi @guardrex, I was fast asleep 😴 when all this action happened.

I will respond within a few hours. You are awesome. Thanks for getting to this so quickly ✨

shrayasr commented 1 year ago

Hi @guardrex

Yes! I totally agree ... and I ran into this exact scenario working on the reference docs. IIRC, I was working on updating the SignalR docs where hub config was shifting over based on the new extension methods. I couldn't find some optons but came to learn that they would appear in the next preview. Indeed, they arrived, and you can see the final result in this section ...

learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-8.0#server-side-circuit-handler-options

We are on NET8 and we are on the rc2 but we still don't see the .AddHubOptions on AddInteractiveServerComponents. Is this in some other assembly that needs to be added as a dependency? We have tried by doing using System; as well. But no avail.

Here is our output from running `dotnet --info` ``` .NET SDK: Version: 8.0.100-rc.2.23502.2 Commit: 0abacfc2b6 Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100-rc.2.23502.2\ .NET workloads installed: There are no installed workloads to display. Host: Version: 8.0.0-rc.2.23479.6 Architecture: x64 Commit: 0b25e38ad3 .NET SDKs installed: 2.1.526 [C:\Program Files\dotnet\sdk] 2.2.110 [C:\Program Files\dotnet\sdk] 2.2.207 [C:\Program Files\dotnet\sdk] 3.1.426 [C:\Program Files\dotnet\sdk] 5.0.103 [C:\Program Files\dotnet\sdk] 5.0.408 [C:\Program Files\dotnet\sdk] 5.0.416 [C:\Program Files\dotnet\sdk] 6.0.319 [C:\Program Files\dotnet\sdk] 7.0.310 [C:\Program Files\dotnet\sdk] 8.0.100-rc.2.23502.2 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-rc.2.23479.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: arm64 [C:\Program Files\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation] x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download ```

Edit: We were looking in the wrong place. We are able to use .AddHubOptions on the builder. Sorry for the confusion.


I'm really happy that you opened this because I'm finding several sneaky bits 😈 that are trying to get past me for migration coverage

I'm so glad that it helped in some way πŸ’ƒπŸ½

app.MapBlazorHub(options => options.CloseOnAuthenticationExpiration = true);

Place it after your call to app.MapRazorComponents.

Unfortunately this didn't work. We are seeing the following error on the console:

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://localhost:5191/_blazor/initializers - - -
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1001]
      2 candidate(s) found for the request path '/_blazor/initializers'
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1005]
      Endpoint 'Blazor initializers' with route pattern '/_blazor/initializers/' is valid for the request path '/_blazor/initializers'
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1005]
      Endpoint '(null)' with route pattern '/_blazor/initializers/' is valid for the request path '/_blazor/initializers'
dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[9]
      Connection id "0HMUMNLG9R88S" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://localhost:5191/_vs/browserLink - 200 - text/javascript;+charset=UTF-8 111.2111ms
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:

      Blazor initializers

         at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(Span`1 candidateState)
         at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, Span`1 candidateState)
         at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, Span`1 candidateState)
         at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[9]
      Connection id "0HMUMNLG9R88R" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://localhost:5191/_blazor/initializers - 500 - text/plain;+charset=utf-8 53.8392ms

And this errors in the browser console

GET http://localhost:5191/_blazor/initializers 500 (Internal Server Error)
(anonymous) @ blazor.web.js:1
(anonymous) @ blazor.web.js:1
startCircutIfNotStarted @ blazor.web.js:1
resolveRendererIdForDescriptor @ blazor.web.js:1
determinePendingOperation @ blazor.web.js:1
refreshRootComponents @ blazor.web.js:1
(anonymous) @ blazor.web.js:1
setTimeout (async)
rootComponentsMayRequireRefresh @ blazor.web.js:1
onDocumentUpdated @ blazor.web.js:1
Ds @ blazor.web.js:1
VM69:1  Uncaught (in promise) SyntaxError: Unexpected token 'M', "Microsoft."... is not valid JSON
await (async)
startCircutIfNotStarted @ blazor.web.js:1
resolveRendererIdForDescriptor @ blazor.web.js:1
determinePendingOperation @ blazor.web.js:1
refreshRootComponents @ blazor.web.js:1
(anonymous) @ blazor.web.js:1
setTimeout (async)
rootComponentsMayRequireRefresh @ blazor.web.js:1
onDocumentUpdated @ blazor.web.js:1
Ds @ blazor.web.js:1
aspnetcore-browser-refresh.js:260  WebSocket connection to 'wss://localhost:44332/BlazorNet8AuthTest/' failed: 
(anonymous) @ aspnetcore-browser-refresh.js:260
getWebSocket @ aspnetcore-browser-refresh.js:257
(anonymous) @ aspnetcore-browser-refresh.js:16
aspnetcore-browser-refresh.js:19 WebSocket failed to connect.

We (@kalai-logicsoft and I) have made a sample project where we are able to replicate this error here for your reference: https://github.com/kalai-logicsoft/BlazorNet8AuthTest

We were wondering if this was because perhaps 2 hubs are being created and they are overlapping?

Let me know if you need more info on this from our end.

guardrex commented 1 year ago

@shrayasr ... Open an issue for the product unit at ...

https://github.com/dotnet/aspnetcore/issues

Please add ...

cc: @guardrex https://github.com/dotnet/AspNetCore.Docs/issues/30843

... to the bottom of your opening comment so that I can follow along. I might re-open this for additional doc work depending on what they say.

shrayasr commented 1 year ago

Gotcha @guardrex. Doing it right away.

pigwing commented 11 months ago

I have encountered exactly the same problem.

pigwing commented 11 months ago

Have you found a solution?

kalai-logicsoft commented 11 months ago

Have you found a solution?

Actually they have updated the documentation to solve this problem look at Here, But it created a new problem which is available here. Waiting on that for their response

guardrex commented 11 months ago

As you're probably aware, we just had the .NET 8 release yesterday. AFAICT, they're still slammed with work related to the release. As Damian said in the .NET Conf keynote, this is probably the largest .NET release to date. There's no ETA for the PU issue, but I'm sure Surayya will get to it as soon as she can.

pixelpandaIO commented 11 months ago

Same here

guardrex commented 7 months ago

There's some new info provided by the PU issue. I'll take a look at adding some guidance (a point-in-time cross-link at least for 8.0 given that some kind of API is planned for .NET 9).

https://github.com/dotnet/aspnetcore/issues/51698#issuecomment-1984340954

guardrex commented 2 months ago

Fixed by #33467.