I'm trying to impersonate another user by code.. I know in Sharepoint Enterprise there's a method which uses the UserProfileManager to impersonate...
I wrote down this "trace code" without know if it is right or wrong... Can anybody suggest me if i'm doing the impersonification in the right way?
private static void impersonateSpecificUser(string username, SPSite site, SPWeb currentWeb)
{
SPUser user = currentWeb.EnsureUser(username);
currentWeb.AllowUnsafeUpdates = true;
HttpRequest request = new HttpRequest("", site.Url, "");
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter(CultureInfo.CurrentCulture)));
HttpContext.Current.Items["HttpHandlerSPWeb"] = currentWeb;
WindowsIdentity wi = WindowsIdentity.GetCurrent();
typeof(WindowsIdentity).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(wi, user.LoginName);
HttpContext.Current.User = new GenericPrincipal(wi, new string[0]);
}
May it work on Sharepoint Foundation??
Thank you very much!!