2013-02-15 74 views
0

我有一個.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); 
+0

順便說一句,您使用的是哪種Umbraco版本? – 2013-02-16 16:29:31

回答

0

如果在刪除代碼之前從代碼隱藏中註銷當前用戶,會發生什麼情況?

它看起來像被刪除的用戶仍然登錄並存在於當前會話,因此一把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並清除當前會話。最後,註銷後,使用其用戶名刪除成員。

+0

同樣的事情。我無法讓FormsAuthentication.SignOut()正常工作,但在這個好站點的幫助下,我通過刪除一些cookie來退出工作。我認爲一旦成員已經退出,我可以將其刪除,但我會放棄會話,所以我不能使用它來允許往返,所以這意味着將它們添加到「刪除隊列」或類似的:/ – 2013-02-15 20:03:07

+0

看到我上面的編輯,這可能會有所幫助。如果沒有,請添加您正在處理註銷的代碼部分。 – 2013-02-15 21:27:40

+0

同樣,我發現一個帖子讓這兩個人解決了一個不同的問題 - 但沒有幫助。我會發布最長版本的代碼,我仍然沒有工作... – 2013-02-16 08:24:31