1. Before acquiring user information required to configure Secure Store Service SSS.
2. The following code is to obtain user information:
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; }
Note: Sometimes being given in place of the red line on the map: Secure Store Service did not performed the operation
Here is the reason for our
Context = SPServiceContext SPServiceContext.GetContext (site) of the site we use SPContext.Current.Site. Therefore, modifications to the code here above
a using (SPSite Site = new new SPSite (WebUrl)) can be resolved properly.
Reproduced in: https: //www.cnblogs.com/lynn-lin/p/4595737.html