I am trying to create my own login system but for some reason it wont add a new user to my MSSMS database
i have already created the migration and the tables are in the database
Startup Code:
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddIdentity
(options => - {
- options.User.RequireUniqueEmail = true;
- }).AddEntityFrameworkStores
() - .AddDefaultTokenProviders();
- services.ConfigureApplicationCookie(config =>
- {
- config.Cookie.Name = "Login_Cookie1";
- config.LoginPath = "/Account/login";
- });
- services.AddDbContext
(options => - options.UseSqlServer(Configuration.GetConnectionString("Master")));
- services.AddControllersWithViews();
- }
appsettings.json:
- "ConnectionStrings": {
- "Master": "Server=LAPTOP-VI29TVE0;Database=MasterDb;Trusted_Connection=True;MultipleActiveResultSets=true"
- }
Controller:
- public class AccountController : Controller
- {
- private UserManager
Usermgr { get; } - private SignInManager
SignInmgr { get; } - public AccountController(UserManager
userManager, - SignInManager
signInManager) - {
- Usermgr = userManager;
- SignInmgr = signInManager;
- }
- public async Task
Register() - {
- var Person = new AppUser();
- Person.UserName = "username1";
- Person.Email = "[email protected]";
- Person.FirstName = "Firstname1";
- Person.LastName = "chees123";
- IdentityResult result = await Usermgr.CreateAsync(Person, "Password");
- if (result.Succeeded)
- {
- ViewBag.Message = "Account was succesfully created";
- }
- else
- {
- ViewBag.Message = "Something went wrong";
- }
- return View();
- }
- }
IdentiyAppContext:
- public class IdentityAppContext : IdentityDbContext
int> - {
- public IdentityAppContext(DbContextOptions
options) - : base(options)
- {
- }
- }
- public class AppUser : IdentityUser<int>
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- }
- public class AppRole : IdentityRole<int> //Identity calm
- {
- }
- @{
- ViewData["Title"] = "Register";
- }
Register
@ViewBag.Message
- "Account" asp-action="Login">Login
Jignesh KumarPosted Mar 14, 2021, 6:01 AM
osyris zosarPosted Mar 14, 2021, 6:10 AM