C
C#10mo ago
Palfi

I need help with an error

I get this error and i need help
1 Reply
Palfi
PalfiOP10mo ago
No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered this is the error i get I have figured out where it is Its either in these lines of Program.cs or in LoginPartial
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
@using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
async void SeedVetUserAndRole(IServiceProvider serviceProvider)
{
var userManager = serviceProvider.GetRequiredService<UserManager<IdentityUser>>(); // Use IdentityUser or Owner if customized
var roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();

string vetEmail = "[email protected]";
string vetPassword = "Vet@1234"; // Ensure this meets your password policy
string roleName = "Admin";

// Ensure the Admin role exists
if (!await roleManager.RoleExistsAsync(roleName))
{
await roleManager.CreateAsync(new IdentityRole(roleName));
}

// Ensure the vet user exists
var vetUser = await userManager.FindByEmailAsync(vetEmail);
if (vetUser == null)
{
vetUser = new IdentityUser { UserName = vetEmail, Email = vetEmail }; // Use Owner if you have extended IdentityUser
var result = await userManager.CreateAsync(vetUser, vetPassword);
if (result.Succeeded)
{
await userManager.AddToRoleAsync(vetUser, roleName);
}
}
}
async void SeedVetUserAndRole(IServiceProvider serviceProvider)
{
var userManager = serviceProvider.GetRequiredService<UserManager<IdentityUser>>(); // Use IdentityUser or Owner if customized
var roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();

string vetEmail = "[email protected]";
string vetPassword = "Vet@1234"; // Ensure this meets your password policy
string roleName = "Admin";

// Ensure the Admin role exists
if (!await roleManager.RoleExistsAsync(roleName))
{
await roleManager.CreateAsync(new IdentityRole(roleName));
}

// Ensure the vet user exists
var vetUser = await userManager.FindByEmailAsync(vetEmail);
if (vetUser == null)
{
vetUser = new IdentityUser { UserName = vetEmail, Email = vetEmail }; // Use Owner if you have extended IdentityUser
var result = await userManager.CreateAsync(vetUser, vetPassword);
if (result.Succeeded)
{
await userManager.AddToRoleAsync(vetUser, roleName);
}
}
}
Specifically this line
var userManager = serviceProvider.GetRequiredService<UserManager<IdentityUser>>(); // Use IdentityUser or Owner if customized
var userManager = serviceProvider.GetRequiredService<UserManager<IdentityUser>>(); // Use IdentityUser or Owner if customized
I want the owner to be the default user and the vet part to be an admin user i have models for both
Want results from more Discord servers?
Add your server