locked
how to check user register in database in mvc ? RRS feed

  • Question

  • User1928394251 posted

    hello . i have 2 table . role & user . i can create new user .but i cant check (is user in database or not )  .

    ======*********=======

    public class Role
    {

    public int RoleID { get; set; }
    public string Rolename { get; set; }
    public string RoleInSystem { get; set; }
    public int UserID { get; set; }
    }

    =====******======

    public class User {
    public int UserID { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public int PassWord { get; set; }
    public int RoleID { get; set; }

    }

    ====*****=====my controller

    public class AccountController : Controller
    {
    Accountcontext db = new Accountcontext();

    public ActionResult Register([Bind(Include = "UserID,Name,Email,PassWord,RoleID")] User User)
    {
    if (ModelState.IsValid)
    {
    db.Users.Add(User);
    db.SaveChanges();
    return RedirectToAction("show");
    }

    return View(User);
    }

    ********=====*******

    public ActionResult Login(FormCollection collection,Accountcontext Account)
    {

    ?????????????????

    }
    return View();
    }

    Monday, January 28, 2019 11:29 AM

All replies

  • User1120430333 posted

    Why are you trying to roll your own? Why can't you use the built-in template that implements user login security called Identity fo an ASP.NET MVC project? 

    Monday, January 28, 2019 8:41 PM
  • User309087305 posted

    you can use

    [Authorize]

    Tuesday, January 29, 2019 4:16 AM