Quantcast
Viewing all articles
Browse latest Browse all 25064

Client Object Model in WebPart

I am in Sharepoint 2013 Standard using the Microsoft.SharePoint.Client.Search dll (Client Object Model) in a webpart because Microsoft.SharePoint.Search is obsolete.

When using the ClientContext.ExecuteQuery() method we get an "401 Unauthorized access error". To solve this issue I have used this piece of code:

System.Net.NetworkCredential cr = new System.Net.NetworkCredential("user", "password");   
clientContext.Credentials = cr;
.....
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery); 

clientContext.ExecuteQuery();
The same code works in a console application with no credentials (without user and password) but in a WebPart I get the 401 Unauthorized access error and the webpart needs to execute the query with the current logged user (I am in a Domain). CacheCredentials.DefaultCredentials or CacheCredentials.DefaultNetworkCredentials is always empty.

Any ideas?

Thanks everyone.


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>