Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear All.
I am trying to build a User authentication in ASP.Net MVC4 from a tutorial. I am already done with 80 % of the project but at the end i have faced with a problem. I couldn't get a clue even googling for an hour.
I have a user control just like below.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Data.EntityModel;
using System.Data.Entity;
using System.Data.EntityClient;
using System.Data.OracleClient;
using System.Data.Objects.SqlClient;



namespace SimplyLogInSystem.Controllers
{
    public class UserController : Controller
    {
        private object sysUser;
        //
        // GET: /User/

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult LogIn()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogIn(Models.UserModel user)
        {
            if (ModelState.IsValid)
            {
                if (IsValid(user.Email, user.Password))
                {
                    FormsAuthentication.SetAuthCookie(user.Email, false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect.");
                }
            }
            return View(user);
        }


        [HttpGet]
        public ActionResult Registration()
        {
            return View();
        }


        [HttpPost]
        public ActionResult Registration(Models.UserModel user)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    var crypto = new SimpleCrypto.PBKDF2();

                    var encrpPass = crypto.Compute(user.Password);

                    var sysUsers = SystemUser.CreateSystemUser(Guid.NewGuid(), user.Email, encrpPass, crypto.Salt);

                    var sysUser = db.SystemUsers.Create();

                    db.SaveChanges();
                    return RedirectToAction ("Index", "Home");
                }
            }
            else
            	{
                    ModelState.AddModelError("", "Registration data is incorrect.");
            	}

            return View();
        }

and i have a model and a view for it.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace SimplyLogInSystem.Models
{
    public class UserModel
    {
        [Required]
        [StringLength(50)]
        [DataType(DataType.EmailAddress)]
        [Display(Name="Email Address:")]
        public string Email { get; set; }


        [Required]
        [DataType(DataType.Password)]
        [StringLength(20, MinimumLength = 6)]
        [Display(Name = "Password:")]
        public string Password { get; set; }

    }
}


The problem i am facing is that when i want to create the System User it ask for reference of .Create() which i don't have a clue on that. Can you help me with that as I am new to MVC and entity framework?
Posted
Comments
Barcelonista Naser 20-Apr-14 2:52am    
I have entered all the entity framework references but even that it doesn't work.
Sergey Alexandrovich Kryukov 20-Apr-14 12:51pm    
Not clear what you are talking about. What does it mean, "reference of .Create()"?
—SA
Barcelonista Naser 21-Apr-14 1:23am    
What is this .Create() ? is it a method a function or what? i don't have a clue.
[no name] 5-May-14 2:18am    
Yes it would ask for the reference if all the assemblies are not present. Please check for all the Dlls in the reference folder. Else create an action that would execute the create functinality.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900