這會將指定的X509證書添加到SharePoint 2010的「可信關係」存儲中。
使用
var cert = new X509Certificate2(@"C:\my_cert.cer");
AddTrustedRootAuthority("My Cert", cert);
的Util
public static void AddTrustedRootAuthority(string name, X509Certificate2 certificate)
{
Type SPTrustedRootAuthorityManagerType = Type.GetType("Microsoft.SharePoint.Administration.SPTrustedRootAuthorityManager, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", true);
Type SPTrustedRootAuthorityType = Type.GetType("Microsoft.SharePoint.Administration.SPTrustedRootAuthority, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c", true);
object manager = SPTrustedRootAuthorityManagerType.GetProperty("LocalOrThrow", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, null);
object authority = Activator.CreateInstance(SPTrustedRootAuthorityType, BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { name, manager, certificate }, null);
SPTrustedRootAuthorityType.GetMethod("Update", Type.EmptyTypes).Invoke(authority, null);
}