I have a .NET usercontrol running on an Umbraco website, and I'd like to be able to delete the current member from the codebehind (I realise that doesn't sound like a great plan, but this did work on a normal ASP.NET Forms site), but calling `System.Web.Security.Membership.DeleteUser(usernameToDelete, trueOrFalse);` gives me (on the page I'm redirecting to):
Yes I am. The longest version of code that still doesn't work is:
// sort out problems with umbraco caches: Member.RemoveMemberFromCache(Member.CurrentMemberId()); Member.ClearMemberFromClient(Member.CurrentMemberId());
// Clear session cookie HttpCookie rSessionCookie = new HttpCookie("ASP.NET_SessionId", ""); rSessionCookie.Expires = DateTime.Now.AddYears(-1); Page.Response.Cookies.Add(rSessionCookie); // Invalidate the Cache on the Client Side
//TODO: this will consistently give an error trying to update a property on a deleted member. Qs: //http://stackoverflow.com/questions/14899945/error-trying-to-delete-current-member //http://our.umbraco.org/forum/core/general/38455-Error-trying-to-delete-current-Member Response.Redirect("/", false);
Clearly it's useful for a member to be able to delete their account. And the problem with any simple solution is that I need to abandon the session - so I can't do it after the redirect easily using the session - I'd have to put it on a message queue or something.
I'm using umbraco v 4.11.1 (Assembly version: 1.0.4715.27659).
Error trying to delete current Member
I have a .NET usercontrol running on an Umbraco website, and I'd like to be able to delete the current member from the codebehind (I realise that doesn't sound like a great plan, but this did work on a normal ASP.NET Forms site), but calling `System.Web.Security.Membership.DeleteUser(usernameToDelete, trueOrFalse);` gives me (on the page I'm redirecting to):
No member with username '[email protected]' exists
Exception Details: System.Configuration.Provider.ProviderException: No member with username '[email protected]' exists
[ProviderException: No member with username '[email protected]' exists]
umbraco.providers.members.UmbracoProfileProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) +346
System.Configuration.SettingsBase.SaveCore() +402
System.Configuration.SettingsBase.Save() +109
System.Web.Profile.ProfileBase.SaveWithAssert() +31
System.Web.Profile.ProfileBase.Save() +72
System.Web.Profile.ProfileModule.OnLeave(Object source, EventArgs eventArgs) +9025062
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Why is it trying to set a property value after I've deleted the user and changed page? I can't see how to set / remove the current Umbraco member.
I don't think it's a good idea to delete a member when he is logged on. Did you try to logout the member first before deleting it?
Jeroen
Yes I am. The longest version of code that still doesn't work is:
// sort out problems with umbraco caches:
Member.RemoveMemberFromCache(Member.CurrentMemberId());
Member.ClearMemberFromClient(Member.CurrentMemberId());
Roles.RemoveUserFromRole(Page.User.Identity.Name, JobShopRoles.RoleNames.Candidate.ToString());
//logout from: http://stackoverflow.com/questions/412300/formsauthentication-signout-does-not-log-the-user-out
FormsAuthentication.SignOut();
Page.Session.Clear(); // This may not be needed -- but can't hurt
Page.Session.Abandon();
// Clear authentication cookie
HttpCookie rFormsCookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
rFormsCookie.Expires = DateTime.Now.AddYears(-1);
Page.Response.Cookies.Add(rFormsCookie);
// Clear session cookie
HttpCookie rSessionCookie = new HttpCookie("ASP.NET_SessionId", "");
rSessionCookie.Expires = DateTime.Now.AddYears(-1);
Page.Response.Cookies.Add(rSessionCookie);
// Invalidate the Cache on the Client Side
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Page.Response.Cache.SetNoStore();
//END logout
System.Web.Security.Membership.DeleteUser(currentUser.UserName, true);
//TODO: this will consistently give an error trying to update a property on a deleted member. Qs:
//http://stackoverflow.com/questions/14899945/error-trying-to-delete-current-member
//http://our.umbraco.org/forum/core/general/38455-Error-trying-to-delete-current-Member
Response.Redirect("/", false);
Clearly it's useful for a member to be able to delete their account. And the problem with any simple solution is that I need to abandon the session - so I can't do it after the redirect easily using the session - I'd have to put it on a message queue or something.
I'm using umbraco v 4.11.1 (Assembly version: 1.0.4715.27659).
is working on a reply...