问题描述
Web api始终将GetClientCertificate
接收为null。它与IISExpress一起使用,无需在IISExpress或IIS上托管证书。证书存在于服务器上的证书存储中。只是想要手动验证,就像客户端发送证书文件和Web api代码通过查看服务器上的证书存储来手动验证证书(没有iis验证)。
在同一问题上经过几篇文章,但它需要在IIS / IISExpress上托管证书。
已尝试: 客户端发送证书如下,并预期在服务器端接收。 客户端发送证书:
var handler = new HttpClientHandler();
X509Store store = new X509Store(StoreName.My,StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var certifcates = store.Certificates.Find(X509FindType.FindByThumbprint,"07a49ef049795a07be786512359be34d234e4548",false);
var cert = certifcates[0];
handler.ClientCertificates.Add(cert);
var client = new HttpClient(handler);
var s ="xml content to post";
var data = new StringContent(s,Encoding.UTF8,"application/xml");
var result = client.PostAsync("http://localhost:51567/api/PostContent",data).GetAwaiter().GetResult();
网络api期望在GetClientCertificate
上接收客户端证书,如下所示,但是它总是为null。
网络API:
var cert = httpActionContext.Request.GetClientCertificate();
if (cert == null)
...
else
..
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)