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
– Marconi
Put the Return Redirecttoaction("Index"); instead of the Return View();
– Netinho Santos
I made the change but did not redirect to Index
– Morais