Skip to content

Instantly share code, notes, and snippets.

@rufer7
Created August 27, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rufer7/4891906042baa1886561 to your computer and use it in GitHub Desktop.
Save rufer7/4891906042baa1886561 to your computer and use it in GitHub Desktop.
An example for impersonate a service reference call
namespace how.To.Impersonate.Service.Reference.Call
{
public static class CurrentUserDataHelper
{
public static String GetCurrentUserId()
{
var administrationService = GetServiceReferenceInstance();
var identity = (WindowsIdentity)HttpContext.Current.User.Identity;
administrationService.Credentials = CredentialCache.DefaultCredentials;
using (var impersonationContext = identity.Impersonate())
{
return administrationService.CurrentUsers.ToList().First().Identity;
}
}
private static Contracts.CurrentUserData.Administration GetServiceReferenceInstance()
{
return new Contracts.CurrentUserData.Administration(new Uri(ConfigurationManager.AppSettings["AKey"]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment