Guest User

Untitled

a guest
Sep 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using System;
  2. using Telerik.Sitefinity.Data;
  3. using Telerik.Sitefinity.Security;
  4.  
  5. namespace SitefinityWebApp
  6. {
  7. public class OrphanedUserProfilesOperations
  8. {
  9. public void DeleteOrphanedUserprofiles()
  10. {
  11. var transactionName = string.Concat("DeleteOrphanProfiles", Guid.NewGuid());
  12. var hasDeletionOccured = false;
  13. var providers = UserProfileManager.ProvidersCollection;
  14.  
  15. foreach (var provider in providers)
  16. {
  17. var profileManager = UserProfileManager.GetManager(provider.Name, transactionName);
  18. var profiles = profileManager.GetUserProfiles();
  19.  
  20. foreach (var profile in profiles)
  21. {
  22. if (profile.User == null)
  23. {
  24. profileManager.Delete(profile);
  25. hasDeletionOccured = true;
  26. }
  27. }
  28. }
  29.  
  30. if (hasDeletionOccured)
  31. {
  32. TransactionManager.CommitTransaction(transactionName);
  33. }
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment