コード例 #1
0
        public async Task <ActionResult> ManageRoles(string action)
        {
            switch (action)
            {
            case "add":
                try
                {
                    //DocSection:AddRole
                    // Attempts to assign the current user to the "KenticoRole" and "CMSBasicUsers" roles
                    IdentityResult addResult = await KenticoUserManager.AddToRolesAsync(CurrentUser.Id, "KenticoRole", "CMSBasicUsers");

                    //EndDocSection:AddRole
                }
                catch (Exception exception)
                {
                    // Adds error messages onto the role management page (for example if the roles do not exist in the system)
                    ModelState.AddModelError("", string.Format("Exception: {0}", exception.Message));
                }

                return(View(CurrentUser));

            case "remove":
                //DocSection:RemoveRole
                // Attempts to remove the "KenticoRole" and "CMSBasicUsers" roles from the current user
                IdentityResult removeResult = await KenticoUserManager.RemoveFromRolesAsync(CurrentUser.Id, "KenticoRole", "CMSBasicUsers");

                //EndDocSection:RemoveRole

                return(View(CurrentUser));

            default:
                return(View(CurrentUser));
            }
        }