我在 Umbraco 网站上运行了一个 .NET 用户控件,我希望能够从代码隐藏中删除当前成员(我意识到这听起来不是一个好计划,但这确实适用于普通的 ASP。 NET Forms 站点),但调用System.Web.Security.Membership.DeleteUser(usernameToDelete, trueOrFalse);
给了我(在我重定向到的页面上):
No member with username 'test10@test.test' exists
Exception Details: System.Configuration.Provider.ProviderException: No member with username 'test10@test.test' exists
[ProviderException: No member with username 'test10@test.test' 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
为什么在我删除用户并更改页面后尝试设置属性值?我看不到如何设置/删除当前的 Umbraco 成员。
编辑:我正在使用 umbraco v 4.11.1(程序集版本:1.0.4715.27659)
这是我尝试过的最长版本的注销代码,但仍然出现错误:
// 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);