Startup.Cs public void ConfigureServices(IServiceCollection services) { //adding this line services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddDbContext<dbcontext>(options => options.UseSqlServer(Configuration.GetConnectionString("sqlconne"))); public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //adding this line app.UseAuthentication(); // I think it is client side user registration?? }
dbcontext.cs public class dbcontext : DbContext { public dbcontext(DbContextOptions<dbcontext> options) : base(options) { } public DbSet<Student> stud{ get; set; } } student.cs public class Student { [Key] public int StudentId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string EmailId { get; set; } public string Password { get; set; } } RegisterController.cs namespace CrudWithoutEf.Controllers { public class RegisterController : Controller { private readonly UserManager<dbContextClass> _userManager; public SignInManager<dbContextClass> _signInManager; public RegisterController(UserManager<dbContextClass> userManager, SignInManager<dbContextClass> signInManager) { _userManager = userManager; _signInManager = signInManager; } [HttpGet] public IActionResult Register() { return View(); } [HttpPost] public async Task<IActionResult> Register(dbContextClass mb) { if (ModelState.IsValid) { //error is dbcontent class is not contain username and password //here i m writing Identity user then give an error var user = new dbContextClass { EmailId = mb.EmailId, Email = mb.Password }; //error is dbcontent class is not contain username and password var result = await _userManager.CreateAsync(user, mb.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, false); return RedirectToAction("Index", "Home"); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return View(mb); } } }
dbContextClass
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)