I need to have a RESTful API that I can call from an MVC5 web app to initially do just simple authentication/authorization against local sql server exclusively. I need to be able to pass login credentials from the web app to the api to get the header token etc. Then I need to be able to check the token for any requests to pull data or save data back to the db. I'm using the tutorial sample app Here right now until I understand the functionality.
the web side is just a form with a button and some jquery to catch the submit button being clicked:
$(document).ready(function () {
var register = function() {
var dataa = {
Email: "[email protected]",
Password: "password",
ConfirmPassword: "password"
};
$.ajax({
type: 'POST',
url: 'api/Account/Register',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(dataa)
});
return false;
}
$('#btnRegister').click(register);
});
and then here is the controller on the api itself:
[Authorize]
[RoutePrefix("api/Account")]
public class AccountController : ApiController
{
[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
if (!result.Succeeded)
{
return GetErrorResult(result);
}
return Ok();
}
}
And it's giving me a 404 error now when I try to click it.