question

6666666 avatar image
0 Votes"
6666666 asked LanHuang-MSFT answered

How to login and logout using signalr?

In a`HubConnection` how to get the login info? how to use a username and password to get the user info?

dotnet-aspnet-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered

Hi @6666666,
HubConnection should be created using HubConnectionBuilder. Before hub methods can be invoked the connection must be started using StartAsync(). Clean up a connection using StopAsync() or DisposeAsync().
I suggest that you can get user information from the Disconnect method in the form of Context.ConnectionId.

You can refer to the following article:
https://docs.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-5.0
https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/mapping-users-to-connections


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Lan Huang

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.