I have a blazor client project which I want to use an API in the same solution. But I can't seem to reach the API. In the blazor project program.cs I have set the BaseAdress like this:
public static async Task Main(string[] args){ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add<App>("app"); builder.Services.AddBlazoredLocalStorage(); builder.Services.AddAuthorizationCore(); builder.Services.AddScoped<AuthenticationStateProvider, ApiAuthenticationStateProvider>(); builder.Services.AddScoped<IAuthService, AuthService>(); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); await builder.Build().RunAsync();}Inside the blazor app I have an Authservice which is trying to call the API. The service's register method looks like this:
public async Task<HttpResponseMessage> Register(UserRegisterViewModel model){ var result = await _httpClient.PostAsJsonAsync("Account/Register", model); return result;}As you can see the Register-method is trying to call a register-action in a account controller, which I have in an API in the same solution. This is the Action:
[Route("Account")][ApiController]public class AccountController : ControllerBase{ private readonly UserManager<ApplicationUser> _userManager; private readonly SignInManager<ApplicationUser> _signInManager; private readonly IConfiguration _configuration; public AccountController(IConfiguration configuration, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager) { _userManager = userManager; _signInManager = signInManager; _configuration = configuration; } [HttpPost] [Route("Register")] public async Task<IActionResult> RegisterAsync([FromBody]UserRegisterViewModel model) { if(!ModelState.IsValid) return BadRequest(ModelState); ApplicationUser user = new ApplicationUser { Email = model.Email, UserName = model.Email }; IdentityResult result = await _userManager.CreateAsync(user, model.Password); if (!result.Succeeded) return BadRequest(result.Errors); return Ok(); } ..... .....}But for some reason I never reach to action RegisterAsync. Why is this? What am I missing?