Опитвам се да използвам вградената в Asp.net система за управление на ролите, но не мога да я подкарам. Опитах с различни подходи. Единият беше да направя Test контролер и да инициализирам няколко потребителя и да им задам роли.
string newRoleName = RoleName.Trim();
if (!Roles.RoleExists(newRoleName)) // here I get timeout error
// Create the role
Roles.CreateRole(newRoleName);
Другият беше следния:
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>()); // here I get this error
// The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.
var appUser = new ApplicationUser
{
UserName = model.Email,
Email = model.Email
};
IdentityResult identityUserResult = UserManager.Create(appUser, model.Password);
roleManager.Create(new IdentityRole("Admin"));
UserManager.AddToRole(appUser.Id, "Admin");
Не знам как да го накарам да работи. Може ли някой да ме насочи? Използвам Azure и .NET 4.5.