Can I use SharePoint client object model in web part?
This code works in my console application, but in a web part it returns "The remote server returned an error: (401) Unauthorized."
The code is:
var siteUrl = "http://www.server.com/";
var clientContext = new ClientContext(siteUrl);
var root = clientContext.Site.RootWeb;
WebCollection collWeb = root.GetSubwebsForCurrentUser(null);
clientContext.Load(root);
clientContext.Load(collWeb);
clientContext.ExecuteQuery();
The problem might be that the client context does not use the current user credentials. What should I do?