SHARE
TWEET

Untitled

a guest Jul 17th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IPrincipal principal = Thread.CurrentPrincipal;
  2. IIdentity identity = principal == null ? null : principal.Identity;
  3. string name = identity == null ? "" : identity.Name;
  4.      
  5. Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
  6.      
  7. string userName = "Fred"; // todo
  8. string[] roles = { "User", "Admin" }; // todo
  9. Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(userName), roles);
  10.      
  11. string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name ;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top