Skip to content

Added sample demonstrating how to connect session with Blazor and WebForms #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 80 commits into from

Conversation

pockets3407
Copy link
Contributor

@pockets3407 pockets3407 commented Jan 11, 2024

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

PR Title
Added sample demonstrating how to connect session with Blazor and WebForms

PR Description
Added sample demonstrating how to connect session with Blazor and WebForms

The only issue I have found is that I get an exception that breaks navigation. This occurs when I navigate from an InteractveServer page (Counter) to a static page (Home, Weather). I'm not sure if this is a different issue.

Addresses #382

@pockets3407
Copy link
Contributor Author

@dotnet-policy-service agree

@twsouthwick
Copy link
Member

@pockets3407
Copy link
Contributor Author

My sample demonstrates sharing session data between Blazor and WebForms with HttpContext added in NET 8. The other sample demonstrates forwarding and displaying Blazor components in WebForms in NET 7. If it would make more sense to combine the two samples, I can do that. I just didn't want to jam everything into one sample.

@twsouthwick
Copy link
Member

Yeah, let's have a one stop-shop for the the blazor/webforms sample. Both are helpful things to show, but it would be greato show how they may complement each other two (and verify that they do!)

@pockets3407
Copy link
Contributor Author

Ok, I will combine them and update the PR on Monday.

@pockets3407
Copy link
Contributor Author

@twsouthwick It looks like Blazor components in WebForms needs Blazor Interactive Server. I don't think I can combine the two unless System.Web.Adapters supports Blazor Interactive Server. As soon as blaozr.server.js loads, I can no longer navigate.

added hello world component to blazor to replicate other sample
@twsouthwick
Copy link
Member

I think we want to figure out why that's happening then. We should be playing nicely with blazor, and if there are issues those should be addressed. If there are limitations that we can't work around, those should be addressed.

@pockets3407
Copy link
Contributor Author

It hangs in RemoteAppSessionStateManager when requesting from Counter (page with Interactive Server) to another page (using static rendering). The request gets to GetSessionDataAsync and hangs at the backchannel request. I set a breakpoint inside PostMapRequestHandler on the framework side and the request exits this event, so I am not sure where this could be holding up.

If it doesn't succeed, it is because the request hits the 100 second timeout.

If it works and finishes before the timeout (rare, but I have reproduced it a few times), I get a status code 400 from SetOrReleaseSessionState, but everything seems to be working fine until you repeat it by going from interactive server to another page.

The current sample that I added can easily reproduce it.

@pockets3407
Copy link
Contributor Author

pockets3407 commented Jan 23, 2024

After further investigation (and gaining a better understanding of what his happening on both the blazor side and systemweb.adapters side), it looks like SessionLoadMiddleware is deadlocking on the blazor server request. When page is requested using InteractiveServer the following 3 requests come through the middelware

  1. GET: /counter
  2. POST: /_blazor/negotiate
  3. CONNECT: /_blazor

I am assuming 2 and 3 are from establishing the SignalR connection with Blazor interactive SSR. When request 3 (Connect) comes through, it will stay open until Blazor sends a disconnect request. Since it stays open, the session is not properly committed and will stay in the heartbeat loop on the framework side.

There is probably a better way to do this, but to temporarily fix it while I edit my sample, I am adding the following:
In UseSystemWebAdapters:

        app.UseWhen(
            (context) => context.Request.Method != HttpMethods.Connect,
            (builder) => builder.UseMiddleware<SessionLoadMiddleware>());

@twsouthwick

@erpardeepkaushik
Copy link

Hi @pockets3407 @twsouthwick is the Issue #382 is resolved? and your new sample is ready to try?

dotnet-policy-service bot and others added 4 commits February 2, 2024 19:26
…t as FabricBot replacement

 Details on the replacement service and the syntax of the new yaml configuration file is available publicly at: https://microsoft.github.io/GitOps/policies/resource-management.html

Please review and merge this PR to complete the process of onboarding to the new service.
FabricBot: Onboarding to GitOps.ResourceManagement because of FabricBot decommissioning
@pockets3407
Copy link
Contributor Author

@twsouthwick Do you have any preference on my suggested fix to get this working with blazor server? Do you want me to open another pull request for it that is separate from the sample?

@pockets3407
Copy link
Contributor Author

I manually added a workaround to the sample, so System.WebAdapters can be used with SignalR.
System.WebAdapters middleware can be ignored when there is a Connect request or the request is coming from Blazor SignalR. I decided to use the former, because I thought HttpMethods.IsConnect() would be more optimized than checking if the path contains "_blazor", but both are shown in the sample. This will be the workaround I will use when 1.4 is released.

@twsouthwick The sample is ready waiting to be approved.

@erpardeepkaushik Feel free to use the sample on my branch. I am not sure when it will be committed to the repo.

@twsouthwick
Copy link
Member

It is merged now. Ping me when it's ready and I'll review it. Sorry again for the delay

Andrew Jank added 28 commits September 6, 2024 16:34
added hello world component to blazor to replicate other sample
added hello world component to blazor to replicate other sample
added hello world component to blazor to replicate other sample
…using System.WebAdapters."

This reverts commit 8724304.
…using System.WebAdapters."

This reverts commit 5881a97.
This reverts commit c868607.
@pockets3407 pockets3407 closed this Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants