How can i get client certificate when he connect to the signalr Hub? My code look like this i read certificate from file and then trying to connect to the hub. I want to create certifate object on hub and read some information from it.
Hub code:
public class ServerHub:Hub
{
public override Task OnConnectedAsync()
{
string connectionId = Context.ConnectionId;
//get certificate ? `X509Certificate2 cert = new X509Certificate2(Certificate);`
return base.OnConnectedAsync();
}
Client code
string Certificate = @"C:\Users\StażCRM\Downloads\sample.cer";
X509Certificate2 cert = new X509Certificate2(Certificate);
string resultsTrue = cert.ToString(true);
// Display the value to the console.
Console.WriteLine(resultsTrue);
// Get the value.
string resultsFalse = cert.ToString(false);
// Display the value to the console.
Console.WriteLine(resultsFalse);
this.id = id;
HubConnection con = new HubConnectionBuilder().WithUrl("https://localhost:44375/ClinicServer",opt=>opt.ClientCertificates.Add(cert)).Build();
con.StartAsync().Wait();
According to this answer, you can get the certificate directly from the HttpContext.
SignalR with Client Certificate Authentication
However, the code is for .NET framework.
When using asp.net core I think you can get the certificate like this
this.Context.GetHttpContext().Connection.ClientCertificate
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.