我正在编写 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
答案 0 :(得分:0)
好吧,我找到了解决方法。
我没有使用登录信息填写NetworkCredential对象,而是在网络服务网址{@ 3}}
发布用户名和密码瞧,没有认证提示。关键是,我的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);