I'm using the microsoft asp.net identity tutorial sample app [Here][1] just until I feel comfortable with the functionality needed for my project. I need to have an API that I can call from a separate MVC web app to do authentication/authorization against a local sql server and 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 added a web app project to that example solution that 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: "password@host.com",
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]
[EnableCors("*","*","*")]
[RoutePrefix("api/Account")]
public class AccountController : ApiController
{
[AllowAnonymous]
[Route("Register")]
[HttpPost]
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();
}
}
When I try to call the Register function on the api I get a 404 error (jquery-1.10.2.js:8720 POST http://localhost:35714/api/Account/Register 404 (Not Found)) in browser. How can I hit the api function from the front end, and can this call be made from my web app Controller or should it be client side?
Added Microsoft.aspnet.cors and microsoft.aspnet.webapi.cors, added config.EnableCors() to webapiconfig.cs and [EnableCors] to the accountcontroller that inherits from apicontroller.