I have a client which consumes my API. I have an endpoint on the API like so:
[Route("api/account")]
[ApiController]
public class AccountController : BaseController
{
private readonly IIdentityProvider _identityProvider;
private string UserId
{
get
{
return User?.FindFirst("AspNetUserId")?.Value;
}
}
public AccountController(IIdentityProvider identityProvider)
{
_identityProvider = identityProvider;
}
[HttpGet]
public IActionResult GetAccount()
{
var user = _identityProvider.GetByAspNetUserId(UserId);
var account = new Account
{
UserName = user.UserName,
Email = user.Email,
EmailConfirmed = user.EmailConfirmed,
PhoneNumber = user.PhoneNumber,
PhoneNumberConfirmed = user.PhoneNumberConfirmed,
TwoFactorEnabled = user.TwoFactorEnabled,
SmsTwoFactorEnabled = user.SmsTwoFactorEnabled
};
return Ok(account);
}
}
My client Vue.js application calls this action like so:
async getAccount(): Promise<Account> {
const result = await this.axios.get(`${this.apiUrl}/account`);
return this.jsonConvert.deserializeObject(result.data, Account);
}
Whenever this is called I get a 500 error. I've put a breakpoint on the start line of the action, but it doesn't get called. But when I call this same action through Postman, it works. There is nothing different in the 2 requests.
However if I change the [HttpGet]
to [HttpGet("test")
and change the vue.js client to await this.axios.get(
${this.apiUrl}/account/test);
it works and hits the breakpoint.
Can anyone explain what I'm doing wrong here?
EDIT:
The following is what is in the inspector of my browser, as you can see there is no useful information here. It just says 500 internal error with no response:
Here is the configure method of my Startup.cs file:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapDefaultControllerRoute();
});
}