c# - SignalR with Certificates -
I want to make a simple signalar application. Using Http Everything works fine, but when I try to use https and certificates the application does not work.
Now, the only thing I want to do is get the client's certificate in the server.
Server (Authentication Handler): Customer (hub) When I So, am I doing wrong? You must also tell IIS to use the client certificate. I My job code and
Public Class Client CertificateConfirmation: Authentication Handler & lt; Customer CertificateOfficial Option & gt; {Safe Override Work & lt; Authentication ticket & gt; AuthenticateCoreAsync () {var cert = context.Get & lt; X509 certificate & gt; ("Ssl.ClientCertificate"); If (cert == null) {return Task.FromResult & lt; AuthenticationTicket & gt; (Empty); } Try {Options.Validator.Validate (cert); } Hold {return work.formersalt & lt; AuthenticationTat & gt; (Empty); } Return tap; }}
var connection = new HubConnection ("https: // localhost: 8080 /" ); Connection.AddClientCertificate (X509Certificate.CreateFromCertFile ("c1.cer")); IHubProxy myHub = connection.CreateHubProxy ("MyHub"); Connection.Start () Wait () .;
var cert = context.get & lt; X509 certificate & gt; ("Ssl.ClientCertificate"); me
null .
web.config to:
& lt; Location path = "signalr" & gt; & Lt; System.webServer & gt; & Lt; Security & gt; & Lt; Login sslFlags = "SslNegotiateCert" /> & Lt; / Safety & gt; & Lt; /system.webServer> & Lt; / Location & gt;
var cert = ServiceCallHelper.GetClientCertificate (); Var url = new URI (Settings.CoreUrl); Var str = String.Format ("https: // {0} / cert_signalr", url.Host); Var hub = new hub connection (str, false); Hub.AddClientCertificate (certificate);
object cert = null; If (! Hub.Context.Request.Environment.TryGetValue ("ssl.ClientCertificate", cert cert)) !! (Cert X509Certificate2 is)) {s_logger.WarnFormat ("Hub {0} without a certificate or cookie", Hub Context.Request.ToString ()); Throw a new exception ("not authenticated"); }
Comments
Post a Comment