【问题标题】:Connect to a SharePoint site when IIS requires client certificates当 IIS 需要客户端证书时连接到 SharePoint 网站
【发布时间】:2015-10-13 21:57:29
【问题描述】:

我目前有一个用 C# 开发的应用程序,可以帮助我管理 Share-point 2013 网站上的权限。最近,我了解到我们可能会丢失本地实例并转移到另一个位于 cac 强制 IIS 后面的实例。我已将我的一个测试站点转换为需要证书,并尝试了几种将证书发送到 IIS 服务器的方法,但我仍然得到 ​​p>

"远程服务器返回错误:(403) Forbidden。

以下是我尝试过的一些事情。

var handler = new WebRequestHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
handler.ClientCertificates.Add(pki.GetClientCertificate());

handler.UseProxy = false;

using (var client = new HttpClient(handler))
{
  context connection code here
}

pki.GetClientCertificate 是一种方法,我在这种情况下返回一个选定的证书是我的 cac 证书。 SharePoint 设计器在没有问题或提示的情况下连接,这很有趣。对此问题的任何帮助将不胜感激。

只是添加一些我尝试过的东西

context.Credentials = new SharePointOnlineCredentials(uli.username, uli.password);

uli 用户名是转换为用户名的证书我有一个进行转换的类。密码是转换为安全字符串的密码。即使将凭据添加到上下文中,我也会收到相同的消息。

【问题讨论】:

    标签: sharepoint smartcard pki cac


    【解决方案1】:

    我在这里找到了一个可行但缓慢的解决方案:

    http://sharepoint.findincity.net/view/635399286724222582121618/ssl-certificate-error-when-using-client-object-model

    唯一的问题是每次调用上下文时我都必须发送证书链。我从此用户代码更改的一件事如下。

    static void context_ExecutingWebRequest(object sender, WebRequestEventArgs e)
    {
     IntPtr ptr = IntPtr.Zero;
     X509Certificate2 certificate = null;
     X509Certificate t = null;
     var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
     store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
    
    
                // Nothing to do if no cert found.
            HttpWebRequest webReq = e.WebRequestExecutor.WebRequest;
            //webReq.Proxy = new WebProxy("http://[ProxyAddress]"); 
            //Specify a proxy address if you need to 
           // X509Certificate cert = pki.GetClientCertificate();
            foreach (X509Certificate c in store.Certificates)
            {
                webReq.ClientCertificates.Add(c);
            }
        }
    

    我只是将我的所有证书转储到请求中,因为我不想每次单击某些内容时都有提示。因此,如果有人有更有效的方法来做到这一点,请告诉我。

    下面的代码显示了客户端上下文的使用以及它如何验证您的证书

    using (context = new ClientContext(siteurl))
                {
                    ServicePointManager.ServerCertificateValidationCallback = delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                         {
                             bool validationResult = true;
                             return validationResult;
                         };
                    context.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(context_ExecutingWebRequest);
    

    //在这一行下面添加你所有的上下文命令 }

    【讨论】:

      猜你喜欢
      • 2011-03-21
      • 1970-01-01
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多