Created
August 27, 2015 14:09
-
-
Save rufer7/4891906042baa1886561 to your computer and use it in GitHub Desktop.
An example for impersonate a service reference call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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