C# Silverlight:使用DataContext(REST)连接具有不同凭据的SharePoint时,阻止身份验证窗口/登录提示

C# Silverlight:使用DataContext(REST)连接具有不同凭据的SharePoint时,阻止身份验证窗口/登录提示,c#,silverlight,sharepoint,rest,datacontext,C#,Silverlight,Sharepoint,Rest,Datacontext,我正在编程一个Silverlight客户端,使用REST在Sharepoint 2010中使用列表。它应该作为一个小工具在用户的Windows桌面上工作 我的要求是,使用特定凭据而不是当前登录的用户登录Sharepoint。它与我粘贴的源代码配合得很好,我能够按预期获取列表内容,但是,每次我运行该软件时,Windows都会在建立与Sharepoint的连接之前向用户显示一个登录框-身份验证窗口 如果用户通过单击“取消”跳过它,则软件的其余部分正常工作 所以我需要阻止这个登录框 Observabl

我正在编程一个Silverlight客户端,使用RESTSharepoint 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);
ObservableCollection allItems=新的ObservableCollection();
ShoutsProxy.TwitterDataContext上下文=新TwitterDataContext(新Uri(webServiceUrl));
context.HttpStack=HttpStack.ClientHttp;
context.Credentials=new System.Net.NetworkCredential(用户名、密码、域);
context.UseDefaultCredentials=false;
DataServiceQuery=DataServiceQuery)context.ShoutBox;
query.BeginExecute(onGetShoutBoxItemsComplete,查询);
所以在“query.beginexecute”行中,一个登录框立即出现

有什么建议吗

来自杜伊斯堡的问候,
阿尔珀·巴尔马兹(Alper Barkmaz)

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

我没有用登录信息填写NetworkCredential对象,而是在web服务URL上发布用户名和密码

瞧,没有身份验证提示。关键是,我的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);
ObservableCollection allItems=新的ObservableCollection();
ShoutsProxy.TwitterDataContext上下文=新TwitterDataContext(新Uri(“http://username:password@域名(domain.com/service.svc),;
context.HttpStack=HttpStack.ClientHttp;
context.Credentials=new System.Net.NetworkCredential();
context.UseDefaultCredentials=false;
DataServiceQuery=DataServiceQuery)context.ShoutBox;
query.BeginExecute(onGetShoutBoxItemsComplete,查询);