获取指定用户的凭据

时间:2011-02-19 15:32:56

标签: c# sharepoint networking credentials

我打算使用Windows服务。此服务必须连接SharePoint服务并为每个用户获取不同的数据。 sharePoint服务根据在呼叫服务之前设置的用户凭据返回数据。

如果可以在需要获取此凭据的任何帐户下运行该服务,我如何通过用户名和用户域获取用户凭据?

1 个答案:

答案 0 :(得分:2)

根据您添加sharepoint服务的方式(Web引用或服务引用),有不同的方法可以使用请求发送凭据。

使用网络参考,您可以添加NetworkCredentials对象:

SomerService ws = ... //instantiate your service
ws.PreAuthenticate = true;
ws.Credentials = new System.Net.NetworkCredentials("username","pw","domain");

如果它是wsHttpBinding的服务引用,那么就像这样:

Service client = ... //instantiate your service
client.ClientCredentials.UserName.UserName = "domain\\username";
client.ClientCredentials.UserName.Password = "password";

然后,您需要为要检索内容的每个用户存储用户名/密码。

如果这是一个pass-thru服务,客户端访问您的服务并代表用户访问sharepoint,则必须设置Kerberos身份验证并允许模拟通过。也许你可以扩展你想要完成的任务。

相关问题