错误试图删除当前成员
我有一个.NET用户控件在Umbraco网站上运行,我希望能够从代码隐藏中删除当前成员(我意识到这听起来不像一个伟大的计划,但这并在一个正常的ASP.NET窗体现场工作),但调用System.Web.Security.Membership.DeleteUser(usernameToDelete, trueOrFalse);
给我(的页面,我重定向到)上:错误试图删除当前成员
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
为什么尝试设置属性值我有后删除了用户并更改了页面?我看不到如何设置/删除当前的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);
如果在删除代码之前从代码隐藏中注销当前用户,会发生什么情况?
它看起来像被删除的用户仍然登录并存在于当前会话,因此一把umbraco profileprovider试图用它做什么...
编辑: 尝试FormsAuthentication注销后,这2种方法,看看如果它可以帮助:
Member.RemoveMemberFromCache(Member.CurrentMemberId());
Member.ClearMemberFromClient(Member.CurrentMemberId());
EDIT2:
我看着UmbracoProfileProvider类,看看是什么原因造成的错误:
public override void SetPropertyValues(SettingsContext context,
SettingsPropertyValueCollection collection) {
string username = (string)context["UserName"];
bool authenticated = (bool)context["IsAuthenticated"];
if (String.IsNullOrEmpty(username) || collection.Count == 0)
return;
Member m = Member.GetMemberFromLoginName(username);
if (m == null)
throw new ProviderException(String.Format("No member with username '{0}' exists", username));
foreach (SettingsPropertyValue spv in collection) {
if (!authenticated && !(bool)spv.Property.Attributes["AllowAnonymous"])
continue;
if (m.getProperty(spv.Name) != null)
m.getProperty(spv.Name).Value = spv.PropertyValue;
}
}
您可以在提供者试图根据用户名检索当前成员后看到您的异常消息。 无论哪种方式你的上下文仍然包含一个用户名或SettingsPropertyValueCollection计数是> 0,所以它似乎你的代码注销成员仍然留下一些东西。
试试这部分,而不是你拥有的所有注销代码:
Member.RemoveMemberFromCache(Member.CurrentMemberId());
Member.ClearMemberFromClient(Member.CurrentMemberId());
FormsAuthentication.SignOut();
Roles.DeleteCookie();
HttpContext.Current.Session.Clear();
System.Web.Security.Membership.DeleteUser(usernameToDelete, false);
这消除并清除缓存和客户端,标志成员出来,删除角色的cookie并清除当前会话。最后,注销后,使用其用户名删除成员。
同样的事情。我无法让FormsAuthentication.SignOut()正常工作,但在这个好站点的帮助下,我通过删除一些cookie来退出工作。我认为一旦成员已经退出,我可以将其删除,但我会放弃会话,所以我不能使用它来允许往返,所以这意味着将它们添加到“删除队列”或类似的:/ – 2013-02-15 20:03:07
看到我上面的编辑,这可能会有所帮助。如果没有,请添加您正在处理注销的代码部分。 – 2013-02-15 21:27:40
同样,我发现一个帖子让这两个人解决了一个不同的问题 - 但没有帮助。我会发布最长版本的代码,我仍然没有工作... – 2013-02-16 08:24:31
顺便说一句,您使用的是哪种Umbraco版本? – 2013-02-16 16:29:31