You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserStorage.cs 847B

12345678910111213141516171819202122232425262728
  1. using System.Linq;
  2. using System.Security.Claims;
  3. using System.Threading;
  4. using iiie.Authentication.DBO;
  5. using Newtonsoft.Json;
  6. namespace iiie.Authentication.Business
  7. {
  8. public static class UserStorage
  9. {
  10. public static BasicUserDbo BasicUserDbo
  11. {
  12. get
  13. {
  14. var claim = ((ClaimsIdentity)Thread.CurrentPrincipal.Identity).Claims.FirstOrDefault(x => x != null && x.Type == "__userdbo__");
  15. if (claim == null)
  16. return null;
  17. return JsonConvert.DeserializeObject<BasicUserDbo>(claim.Value);
  18. }
  19. set
  20. {
  21. var claim = new Claim("__userdbo__", JsonConvert.SerializeObject(value));
  22. ((ClaimsIdentity)Thread.CurrentPrincipal.Identity).AddClaim(claim);
  23. }
  24. }
  25. }
  26. }