1.在用Secure Store Service獲取用戶信息以前須要配置SSS。web
2.如下代碼是獲取用戶信息:app
using (SPSite site = new SPSite(webUrl)) { SecureStoreProvider prov = new SecureStoreProvider(); SPServiceContext context = SPServiceContext.GetContext(site); prov.Context = context; //current user information try { SecureStoreCredentialCollection cc = prov.GetCredentials(appId); for (int i = 0; i < cc.Count; i++) { ISecureStoreCredential c = cc[i]; IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(c.Credential); string sDecrypString = System.Runtime.InteropServices.Marshal.PtrToStringUni(ptr); credentialList.Add(sDecrypString); } } catch (Exception ex) { throw ex; }
注意:有的時候會在上圖紅線的地方報錯:Secure Store Service did not performed the operationide
形成這裏的緣由是咱們的spa
SPServiceContext context = SPServiceContext.GetContext(site)的site咱們用的SPContext.Current.Site.因此將此處的代碼修改爲如上
using (SPSite site = new SPSite(webUrl))就能夠正常解決。