You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开发SharePoint Server 2019 WebPart时找不到SecureStoreProvider类

解决方案:SharePoint Server 2019 Standard中访问Secure Store Service的可行方案

一、先确认Secure Store Service的基础部署状态

  • 打开SharePoint管理中心,进入应用程序管理 -> 管理服务应用程序,检查是否存在Secure Store Service应用程序且状态为运行中。
  • 用PowerShell验证服务实例状态:
    Get-SPServiceInstance | Where-Object {$_.TypeName -eq "Secure Store Service"}
    
    如果状态不是Online,启动对应的服务实例。

二、正确引用程序集(避免手动找DLL)

  • 不要直接在磁盘搜索DLL,通过Visual Studio的GAC引用更可靠:
    1. 在项目中右键添加引用 -> 选择程序集 -> 框架 -> 扩展,找到Microsoft.Office.SecureStoreService.Server(版本16.0.0.0)并添加。
    2. 如果扩展列表中没有,直接浏览到GAC路径C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.SecureStoreService.Server,选择对应版本的DLL。
  • 若GAC中也没有该程序集,说明SharePoint安装时未包含Secure Store组件:
    1. 打开控制面板 -> 程序和功能,找到Microsoft SharePoint Server 2019,点击更改。
    2. 在安装向导中选择添加或删除功能,确保勾选Secure Store Service组件,完成安装后运行PSConfig.exe更新配置。

三、服务器端访问Secure Store的代码示例

如果已正确引用程序集,使用以下代码访问Secure Store(符合SharePoint最佳实践,替代直接实例化SecureStoreProvider的方式):

using Microsoft.Office.SecureStoreService.Server;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

public SecureStoreCredentialCollection GetSecureStoreCredentials(string targetAppId)
{
    if (string.IsNullOrEmpty(targetAppId)) throw new ArgumentNullException(nameof(targetAppId));
    
    // 获取Secure Store服务代理
    var secureStoreProxy = SPFarm.Local.ServiceProxies.GetValue<SecureStoreServiceProxy>();
    if (secureStoreProxy == null) throw new InvalidOperationException("Secure Store Service代理未找到");

    // 获取Secure Store操作实例
    using (var secureStore = secureStoreProxy.GetSecureStore(SPContext.Current.Site))
    {
        // 验证目标应用程序是否存在
        if (!secureStore.DoesApplicationExist(targetAppId)) throw new InvalidOperationException($"目标应用程序 {targetAppId} 不存在");
        
        // 获取凭据集合
        return secureStore.GetCredentials(targetAppId);
    }
}

四、补丁与配置排查

  • 重新运行SharePoint配置向导(PSConfig.exe):补丁安装后可能需要执行配置更新,才能让程序集生效。
  • 检查已安装的SharePoint累积更新:确保所有后续累积更新已安装,部分补丁可能调整了程序集的位置或命名。

内容的提问来源于stack exchange,提问作者Andrew Malcolm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:37:26