I'm programming a Silverlight client to consume a list in Sharepoint 2010 using REST. It's supposed to work as a gadget on users Windows desktop.
My requirement is, logging into Sharepoint with specific credentials instead of current logged user. It works fine with the source code I pasted down and I'm able to fetch the list content as expected, however, everytime I run the software, Windows shows a login box - authentication window to user before estabilishing a connection to Sharepoint.
If user skips it by clicking "cancel" the rest of software works normally.
So I need to prevent this login box.
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);
So at exactly "query.beginexecute" line, a login box comes up immediately.
Any suggestions?
Greetings from Duisburg, Alper Barkmaz
Answer: 1
Well, I have found a workaround for this.
Instead of filling out a NetworkCredential object with login information, I post username and password at web service URL, http://username:password@domain.com/service.svc
And voila, there's no authentication prompt. The point was, my silverlight application was hosted in local html file with address starting with file://, thus transferring network credentials to target domain was having problems. So in this case, instead of dealing this inside Silverlight, I directly modified the URL and the result was brilliant.
Security: I believe httpclient breaks in, does authentication and removes the login information from URL, so the login information is not transferred over network as plain text. However, double checking this is better.
The new form of solution is,
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);
by : midwinterhttp://stackoverflow.com/users/1318167
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog