为什么我们在AccountController中使用Disassociate操作?

时间:2014-05-31 10:30:28

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

此代码由Visual studio自动生成

 [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Disassociate(string provider, string providerUserId)
    {
        string ownerAccount = OAuthWebSecurity.GetUserName(provider, providerUserId);
        ManageMessageId? message = null;

        // Only disassociate the account if the currently logged in user is the owner
        if (ownerAccount == User.Identity.Name)
        {
            // Use a transaction to prevent the user from deleting their last login credential
            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
            {
                bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));
                if (hasLocalAccount || OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name).Count > 1)
                {
                    OAuthWebSecurity.DeleteAccount(provider, providerUserId);
                    scope.Complete();
                    message = ManageMessageId.RemoveLoginSuccess;
                }
            }
        }

        return RedirectToAction("Manage", new { Message = message });
    }

为什么我们在Mvc的AccountController中使用Disassociate动作?

1 个答案:

答案 0 :(得分:1)

Disassociate操作用于从用户中删除关联帐户(Google,Facebook,Microsoft等)。

在默认的MVC5 AccountController中,它的唯一用途是在“管理帐户”页面上,只有当用户拥有本地密码或用户有多个链接帐户时才会显示。