Logoff after editing a User Role

Asked

Viewed 70 times

0

I am working on an Asp.net-mvc project and would like to force the user logoff after editing a role belonging to the user, using Asp.net-Identity

public async Task<ActionResult> Edit(string id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        var role = await RoleManager.FindByIdAsync(id);
        if (role == null)
        {
            return HttpNotFound();
        }
        RoleViewModel roleModel = new RoleViewModel { Id = role.Id, Name = role.Name };
        return View(roleModel);
    }

    //
    // POST: /Roles/Edit/5
    [HttpPost]

    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Edit([Bind(Include = "Name,Id")] RoleViewModel roleModel)
    {
        if (ModelState.IsValid)
        {
            var role = await RoleManager.FindByIdAsync(roleModel.Id);
            role.Name = roleModel.Name;
            await RoleManager.UpdateAsync(role);
            return RedirectToAction("Index");
        }
        var autheticationUser = HttpContext.Current.GetOwinContext().Authentication;
        autheticationUser.SignOut();
        return View();
    }
  • Take a look at the last reply: https://stackoverflow.com/questions/36766191/asp-net-identity-add-another-user-to-role-instantly-they-dont-have-to-log-out

  • Put the Return Redirecttoaction("Index"); instead of the Return View();

  • I made the change but did not redirect to Index

1 answer

0

Try the following section.

var autheticationUser = HttpContext.Current.GetOwinContext().Authentication;
autheticationUser.SignOut();
  • I would like it right after editing a scroll the application to log off the user

  • You entered this code into your action right after the role edit?

  • I inserted right after editing the scroll

  • Put your code in the question.

  • I changed the question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.