Mitchelln11
Active member
- Joined
- Apr 10, 2020
- Messages
- 39
- Programming Experience
- Beginner
Having issues logging out after deleting a user
I have 2 tables:
dbo.AspNetUsers
dbo.People
I have an ActionLink on the Person Details View that passes the ID:
Then, I'm going to a Delete Action which removes the person AND its AspNetUser record:
1. Button directs to Delete Action as it should
2. Id passing through is correct
3. People person is the correct person
4. Identity user has the right info, most importantly an ID that matches the person's Application ID
5. person is removed
6. Changes are saved
7. AspNetUser record removed
8. Changes saved
9. When it redirects to to the Index View of the People, the navbar still says Hello person@email.com! (Even though the 2 records referencing that email has been deleted)
I have 2 tables:
dbo.AspNetUsers
dbo.People
I have an ActionLink on the Person Details View that passes the ID:
C#:
@Html.ActionLink("Delete Profile", "Delete", "Hiker", new { id = Model.Id }, new { @class = "btn btn-danger" })
Then, I'm going to a Delete Action which removes the person AND its AspNetUser record:
C#:
// POST: PeopleController/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
People person = _context.People.Find(id);
IdentityUser user = _context.Users.Where(s => s.Id == person.ApplicationId).FirstOrDefault();
try
{
_context.People.Remove(person);
_context.SaveChanges();
_context.Users.Remove(user);
_context.SaveChanges();
// User.Logout() or something like it here???
return RedirectToAction("Index", "People");
}
catch
{
return View();
}
}
1. Button directs to Delete Action as it should
2. Id passing through is correct
3. People person is the correct person
4. Identity user has the right info, most importantly an ID that matches the person's Application ID
5. person is removed
6. Changes are saved
7. AspNetUser record removed
8. Changes saved
9. When it redirects to to the Index View of the People, the navbar still says Hello person@email.com! (Even though the 2 records referencing that email has been deleted)