3
你如何以編程方式登錄到asp.net身份2?這對於Web API是直接的,但是僅MVC項目需要__RequestVerificationToken。這是一種登錄方法:如何以編程方式登錄到ASP.NET身份2?
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.Email, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
通過編程的方式,你的意思是類似於單元測試嗎? – Catto