I'm trying to put the current user logged in my MVC 5 application (with windows authentication) into the Author and Editor fields of a new ListItem.
I didn't succeed to just pass the user credentials to the SharePoint Client context, so I tried to edit these two fields instead using SharePoint Client Object Model
using SP = Microsoft.SharePoint.Client;
...
SP.User SPuser = context.Web.EnsureUser(Request.LogonUserIdentity.Name);
//SP.User SPuser = context.Web.EnsureUser("mydomain\\someuser"); //same result as above
context.Load(SPuser);
context.ExecuteQuery();
SP.FieldUserValue userValue = new SP.FieldUserValue();
userValue.LookupId = SPuser.Id;
SP.ListItem documentLi = documentFile.ListItemAllFields;
...
//We don't want the application pool identity here, but the current user
documentLi["Author"] = userValue;
documentLi["Editor"] = userValue;
documentLi.Update();
context.ExecuteQuery();
It works fine in localhost, but nothing happens when I try it on the server : these two fields keeps the application pool identity.
What did I miss ?