Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Telerik.Sitefinity.Data;
- using Telerik.Sitefinity.Security;
- namespace SitefinityWebApp
- {
- public class OrphanedUserProfilesOperations
- {
- public void DeleteOrphanedUserprofiles()
- {
- var transactionName = string.Concat("DeleteOrphanProfiles", Guid.NewGuid());
- var hasDeletionOccured = false;
- var providers = UserProfileManager.ProvidersCollection;
- foreach (var provider in providers)
- {
- var profileManager = UserProfileManager.GetManager(provider.Name, transactionName);
- var profiles = profileManager.GetUserProfiles();
- foreach (var profile in profiles)
- {
- if (profile.User == null)
- {
- profileManager.Delete(profile);
- hasDeletionOccured = true;
- }
- }
- }
- if (hasDeletionOccured)
- {
- TransactionManager.CommitTransaction(transactionName);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment