Help setting up ASP.NET Core Identity and SQL Server
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using SalonML_API.Data;
using SalonML_API.Data.Models;
namespace SalonML_API.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class SeedController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly RoleManager<IdentityRole> _roleManager;
private readonly UserManager<ApplicationUser> _userManager;
private readonly IConfiguration _configuration;
public SeedController(
ApplicationDbContext context,
RoleManager<IdentityRole> roleManager,
UserManager<ApplicationUser> userManager,
IConfiguration configuration)
{
_context = context;
_roleManager = roleManager;
_userManager = userManager;
_configuration = configuration;
}
[HttpGet]
public async Task<IActionResult> ImportLoremIpsum()
{
throw new NotImplementedException();
}
[HttpGet]
public async Task<IActionResult> CreateDefaultUsers()
{
// create the Administrator role
string role_Administrator = "Administrator";
if (await _roleManager.FindByNameAsync(role_Administrator) == null)
await _roleManager.CreateAsync(new IdentityRole(role_Administrator));using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using SalonML_API.Data;
using SalonML_API.Data.Models;
namespace SalonML_API.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class SeedController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly RoleManager<IdentityRole> _roleManager;
private readonly UserManager<ApplicationUser> _userManager;
private readonly IConfiguration _configuration;
public SeedController(
ApplicationDbContext context,
RoleManager<IdentityRole> roleManager,
UserManager<ApplicationUser> userManager,
IConfiguration configuration)
{
_context = context;
_roleManager = roleManager;
_userManager = userManager;
_configuration = configuration;
}
[HttpGet]
public async Task<IActionResult> ImportLoremIpsum()
{
throw new NotImplementedException();
}
[HttpGet]
public async Task<IActionResult> CreateDefaultUsers()
{
// create the Administrator role
string role_Administrator = "Administrator";
if (await _roleManager.FindByNameAsync(role_Administrator) == null)
await _roleManager.CreateAsync(new IdentityRole(role_Administrator));I get an error on the second to last line
"Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'AspNetRoles'."
I'm looking at the SSMS and there are no databases/tables related to users... I was expecting the databases and tables to be made automatically if it finds them missing
Is there some kind of configuration I need to do?