I am writing an account management controller and have to process deleting of own user's account separately:
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(string userName, string confirmButton)
{
MembershipService.DeleteUser(userName);
if (User.Identity.Name.Equals(userName,
StringComparison.InvariantCultureIgnoreCase))
{
FormsAuth.SignOut();
return View("DeleteSelf");
}
else
return RedirectToAction("Index");
}
But partial view LogOnUserControl.ascx still shows just logged out user name while displaying DeleteSelf view because Request.IsAuthenticated and Page.User.Identity values are still set after FormsAuth.SignOut().
Adding a new action ShowDeleteSelfMessage could solve the problem but I don't like this solution:
...
{
FormsAuth.SignOut();
return RedirectToAction("ShowDeleteSelfMessage");
}
...
public ActionResult ShowDeleteSelfMessage()
{
return View("DeleteSelf");
}
Any other ideas? Thank you!