title: How to force logout user when his/her username is changed by another user?
body: <p>In my application I am using Forms-Authentication to sign in and sign out users. </p>
  
  <p>One functionality is admin can change the username of other users. In that case, I need to sign out the user whose username is changed. </p>
  
  <p>If I do not, due to their cookies set before, they gain access to application and receive error messages (since their username does not exist and there are parts where I use their username for some functionality).</p>
  
  <p>How can I force these users to log out using Forms-Authentication ?</p>
  
  <p><strong>UPDATE :</strong></p>
  
  <pre><code>    public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          string controller = filterContext.RouteData.Values["controller"].ToString();
          string action     = filterContext.RouteData.Values["action"].ToString(); ;
          // Below returns the previous username, which does not exist anymore in db.
          string userName = HttpContext.Current.User.Identity.Name;
  
          UnitOfWork unitOfWork = new UnitOfWork();
  
          if (!unitOfWork.UserRepository.UserExists(userName))
          {
              FormsAuthentication.SignOut();
              filterContext.HttpContext.Session.Clear();
              filterContext.HttpContext.Session.Abandon();
              // I am not using Roles.
  
  
          }
          unitOfWork.Dispose();
          base.OnActionExecuting(filterContext);
  
      }
  </code></pre>
  
  <p>In my customer global filter, I check whether user exist or not, if not I sign them out. However, it is not working. By working I mean they pass the authentication and gain access to application.</p>
  
  <p>Thanks in advance.</p>