0

我正在编写一个Silverlight客户端,以使用REST在Sharepoint 2010中使用一个列表。它应该作为用户 Windows 桌面上的小工具工作。

我的要求是,使用特定凭据而不是当前登录的用户登录 Sharepoint。它适用于我粘贴的源代码,并且我能够按预期获取列表内容,但是,每次我运行该软件时,Windows都会在建立与 Sharepoint 的连接之前向用户显示一个登录框 - 身份验证窗口。

如果用户通过单击“取消”跳过它,其余软件将正常工作。

所以我需要阻止这个登录框。

ObservableCollection<ShoutBoxItem> allItems = new ObservableCollection<ShoutBoxItem>();  
ShoutsProxy.TwitterDataContext context = new TwitterDataContext(new Uri(webServiceUrl));

context.HttpStack = HttpStack.ClientHttp;
context.Credentials = new System.Net.NetworkCredential(username, password, domain);
context.UseDefaultCredentials = false;

DataServiceQuery<ShoutBoxItem> query = DataServiceQuery<ShoutBoxItem>)context.ShoutBox;
query.BeginExecute(onGetShoutBoxItemsComplete, query);

因此,恰好在“query.beginexecute”行,会立即出现一个登录框。

有什么建议么?

来自杜伊斯堡的问候,Alper Barkmaz

4

1 回答 1

0

好吧,我已经找到了解决方法。

我没有使用登录信息填写 NetworkCredential 对象,而是在 Web 服务 URL http://username:password@domain.com/service.svc上发布用户名和密码

瞧,没有身份验证提示。关键是,我的 silverlight 应用程序托管在本地 html 文件中,地址以 file:// 开头,因此将网络凭据传输到目标域存在问题。所以在这种情况下,我没有在 Silverlight 中处理这个,而是直接修改了 URL,结果非常棒。

安全性:我相信 httpclient 会入侵,进行身份验证并从 URL 中删除登录信息,因此登录信息不会以纯文本形式通过网络传输。但是,仔细检查这一点会更好。

新的解决方案是,

ObservableCollection<ShoutBoxItem> allItems = new ObservableCollection<ShoutBoxItem>();  
ShoutsProxy.TwitterDataContext context = new TwitterDataContext(new Uri("http://username:password@domain.com/service.svc"));

context.HttpStack = HttpStack.ClientHttp;
context.Credentials = new System.Net.NetworkCredential();
context.UseDefaultCredentials = false;

DataServiceQuery<ShoutBoxItem> query = DataServiceQuery<ShoutBoxItem>)context.ShoutBox;
query.BeginExecute(onGetShoutBoxItemsComplete, query);
于 2012-08-28T15:08:20.110 回答