[RESOLVED]Deleting a user from the AspNetUsers table??

 public ActionResult Delete(string UserId)
        {
            var c = db.Consultants.Find(UserId);
            if (c == null)
            {
                return HttpNotFound();
            }
            return View(db.Consultants.Find(UserId));
        }
 [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(string UserId, FormCollection collection)
        {
            try
            {
                var c = db.Consultants.Find(UserId);
                db.Consultants.Remove(c);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch { return View(); }
        }

I need to be able to delete a Consultant from the database and this works fine except there being one problem.  

I’m not sure how to associate my controller with the DB tables not included in the edmx.  Therefore, the above code doesn’t delete the record from the AspNetUsers and AspNetRoles table in the DB.  

Can you please help me with this????

Thx

You have different dbcontext for user management.

If you have users db objects in your domain db, just change the db connectuin string to you identity connection

like this for default dbcontext for asp.net identity

            using (var db=new ApplicationDbContext())
            {
               
                var user=db.Users.Find(userid);
                db.Users.Remove(user);
                db.SaveChanges();
            }

Leave a Reply