2012-03-23 13 views
0

c#とSharePoint 2010 apisを使用して、証明書をSharePoint 2010(信頼できるIDプロバイダに使用される証明書でチェーン証明書)にインポートするにはどうすればよいですか?Visual Studio(C#)のSPTrustedRootAuthority

PowerShellには新しいSPTrustedRootAuthorityがありますが、私はpowershellを使用できません。 私はdllでリフレクションを使用し、New-SPTrustedRootAuthorityは内部のSPTrustedRootAuthorityManagerクラスを使用しています。

アイデア?

答えて

1

これは、指定された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); 
} 
関連する問題