我试图通过webapi登录用户。我的apicontroller函数是:
public async Task<IHttpActionResult> Login(string email, string password)
{
ApplicationDbContext ctx = new ApplicationDbContext();
UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(ctx);
UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
var user = await UserManager.FindAsync(email, password);
if (user != null)
{
await SignInAsync(user, true); // The name 'SignInAsync' does not exist in current context
return Ok("OK");
}
return Ok("Error");
}
我想在webapi中编写注册,登录和注销的方法,但我被困在SignInAsync
。我是不是漏掉了图书馆参考资料?或者如何在webapi中使用它?
SignInAsync
是SignInManager
类的一个方法,而不是控制器类。
await HttpContext.Current.GetOwinContext()
.Get<ApplicationSignInManager>().SignInAsync(user, true, false);