SharePoint: How to Authenticate with C #
Make the user you want to run the code known in SharePoint, then using
SPSite.RootWeb.EnsureUser("username").UserToken
you can get this user SPUserToken use this to open SPSite like
var token = SPSite.RootWeb.EnsureUser("usernameToImpersonate").UserToken;
using (SPSite site = new SPSite(token, this.ListAddress))
{
using (SPWeb web = site.OpenWeb())
{
// code here will be executed as selected user
}
}
source to share
Running the code above will authenticate under the current user ID, that is, the ID of the user running the current thread.
You can run code as a different user using the NetworkCredntial class in conjunction with the WindowsIdentity class
See these two parts:
http://msdn.microsoft.com/en-us/library/system.net.networkcredential%28VS.71%29.aspx
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx
source to share
It is not clear what you want to make from the question. However, if you are looking for impersonation, note that you can pass an SPUserToken object to the SPSite constructor .
Any objects that you then create on the impersonated SPSite object will behave as if they were created by that user.
source to share