Hello , I am trying to make a custom login page . On adding the password to AspNetUsers I get the following error : Cannot insert explicit value for identity column in table 'AspNetUsers' when IDENTITY_INSERT is set to OFF. Source Error: Line 86: Line 87: var user = new ApplicationUser() { UserName = model.UserName }; Line 88: var result = await UserManager.CreateAsync(user, model.Password); Line 89: ApplicationUser appusr = new ApplicationUser(); Line 90: IdentityUserRole idnt = new IdentityUserRole(); Is there any way to solve this without changing the identity column . The default field is Id nvarchar(128) .
AnCristina
Posts
-
Asp Mvc 5 user registration fails -
ASP MVC 5 application usersIt worked . Thank you very much ! :)
-
ASP MVC 5 application usersOk , I got stuck again . So I created the classes : Role :
public class Role { public Role() { } public Role(string name, int id):this() { this.RoleId = id; this.Name = name; } \[Key\] \[Required\] public virtual int RoleId { get; set; } public virtual string Name { get; set; } }
Permission :
public Permission() { } public Permission(string name,int id):this() { this.Name=name; this.Id = id; } \[Key\] \[Required\] public virtual int Id { get; set; } public virtual string Name { get; set; } }
RolePermission :
public class RolePermission { public Role Role { get; set; } public Permission Group { get; set; } \[Required\] public int RoleGroupId { get; set; } public RolePermission() { } }
I updated the ApplicationUser class
public class ApplicationUser : IdentityUser { public ApplicationUser() : base() { this.Permission=new HashSet(); } \[Required\] public string Name { get; set; } public virtual ICollection Permission { get; set; } }
Is this correct up to this point ? I suppose I should modify the ApplicationDbContext , which , up to this point , looks like this :
public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base("DefaultConnection") { } }
What changes should I do ?
-
ASP MVC 5 application usersThank you very much ! :)
-
ASP MVC 5 application usersOk , in other words I should have three classes : Role Permission RolePermission(in which I should include two objects , one of type Role , and one of type Permission) And I should link the RolePermission to the ApplicationUser , then apply the migration . Is that correct ?
-
ASP MVC 5 application usersHello ! I am building a MVC 5 app in which there will be 4 types of users . (Admin , HR Member , Managers , Employee) . I already created the views and the controllers for each type . I want to give each manager access to certain departments , and the employee access to data according to his employeeID value . After reading several articles on the Internet about this topic , I suppose I have to assign each user type a role and each department/employeeID a permission , but I have no clue on how to do that . Can someone explain to me how to implement this ? I mention that the Identity Framework installed on the project is at version 1.0 .
-
LINQ sums for distinct valuesHello ! I have the following values . ________________________________________ Department ID|||||Income ---------------------------------------- 100 ||||| 350 200 ||||| 500 300 ||||| 450 100 ||||| 600 500 ||||| 550 200 ||||| 700 _______________________________________ How can I get the sum of Income for each Department ID , providing that the values come from separate tables ? I want to display each distinct department id too .
-
MVC 5 Scaffolded view problemI created the view , but renamed it , so the controller didn't recognize it . Thanks !
-
MVC 5 Scaffolded view problemProblem solved , apparently my view wasn't named properly .
-
MVC 5 Scaffolded view problemHello ! I want to create a MVC 5 application using Visual Studio 2013 . I have the following problem : I created a controller to display data from a table and then created a view using Add View for the
return View();
method . The view is created , but when I try to go to the view from the controller , the "Unable to find a matching view" error is shown . How can I link the view to the controller ? Sorry if this question was asked before .
-
MVC 4 Local DatabaseI managed to solve the problem by creating the model using an existing database . Thanks !
-
MVC 4 Local DatabaseHello ! I want to build a MVC 4 app database using Entity Framework Code First . I have the following problem : I've tried to create a local database with 2 tables in it (I declared 2 classes and then attached them in a DbContext class) , and then wrote the following connection string :
The database doesn't seem to be created after running the application , since it doesn't appear in the Server Explorer and in the App_Data Folder . I use Visual Studio 2012 . Can you please help me solve this problem ?