2

Currently I am working on .net web api's that are called from non-SharePoint pages to run SharePoint code to perform certain actions. I have shared configured visual studio so that every one can access the page through my system's IP URL. The code in web api is working fine expect for the fact that it is always taking my account to perform every action.

So how can we run the client context from another users account if I have the domain name of the user.

ClientContext clientContext = new ClientContext(siteUrl);
Web web = clientContext.Web;
User user = web.EnsureUser(@"domain\user1");
clientContext.Load(user);
clientContext.ExecuteQuery();
string title = user.Title;
string loginName = user.LoginName;

If I want to run the clientcontext under this user name. How can i do that. I found the code below that works in server side

SPUserToken userToken = web.AllUsers[user].UserToken;
SPSite s = new SPSite(siteStr, userToken);
SPWeb w = s.OpenWeb();
Console.WriteLine("Currently logged in as: " +
                  w.CurrentUser.ToString() +
                  "(" + w.CurrentUser.Name + ")"
                 );

What is the alternative for this code in CSOM.

Thanks in advance

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.