public async Task<IActionResult> CreateRole()
{
foreach (UserRole item in Enum.GetValues(typeof(UserRole)))
{
if (await _roleManager.FindByNameAsync(item.ToString()) == null)
{
await _roleManager.CreateAsync(new IdentityRole()
{
Name = item.ToString(),
});
}
}
return RedirectToAction("Index", "Home");
}
when i write account/createrole/ in the url part in may localhost the roles can not be created. i didnt know why because i checked that for many times.
Ensure that you have set up the routing correctly in your Startup.cs file. It should map the URL path "account/createrole/" to the CreateRole action in your controller.
// Startup.cs
Make sure that the controller where this action correctly decorated with the [Controller] attribute.