Guest User

Untitled

a guest
Jun 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. string[] roles = { "User", "Admin" };
  2. Thread.CurrentPrincipal = new GenericPrincipal(
  3. new GenericIdentity("Fred"), roles);
  4.  
  5. [PrincipalPermission(SecurityAction.Demand, Role = "Admin")]
  6. void SomeAdminFunction() { }
  7.  
  8. public static string GetUsername() {
  9. IPrincipal principal = Thread.CurrentPrincipal;
  10. IIdentity identity = principal == null ? null : principal.Identity;
  11. return identity == null ? null : identity.Name;
  12. }
  13. public static bool IsInRole(string role) {
  14. IPrincipal principal = Thread.CurrentPrincipal;
  15. return principal == null ? false : principal.IsInRole(role);
  16. }
  17.  
  18. row.UpdatedBy = MyUtilityClass.GetUsername();
Add Comment
Please, Sign In to add comment