I am trying to log in via Web API 2. What I did was copy some code from AccountController from MVC 5.2, but when I run this code, ApplicationSignInManager nulland it throws an exception.
I can not find sample projects on Github or ASP.NET.
This is my UserController web user API.
[RoutePrefix("api/users")]
public class UserController : ApiController
{
...
[Route("login")]
[HttpPost]
public HttpResponseMessage Login(LoginViewModel model)
{
if (!ModelState.IsValid)
{
return new HttpResponseMessage(HttpStatusCode.Forbidden);
}
var signinManager = Request.GetOwinContext().Get<ApplicationSignInManager>();
SignInStatus result =
signinManager.PasswordSignIn(model.Email, model.Password, model.RememberMe, false);
switch (result)
{
case SignInStatus.Success:
return new HttpResponseMessage(HttpStatusCode.OK);
default:
return new HttpResponseMessage(HttpStatusCode.Forbidden);
}
}
}
What am I doing wrong?
source
share