【发布时间】:2017-12-22 15:24:24
【问题描述】:
有什么区别:
public ActionResult Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
IdentityResult result = IdentityManager.Authentication.CheckPasswordAndSignIn(AuthenticationManager, model.UserName, model.Password, model.RememberMe);
if (result.Success)
{
return Redirect("~/home");
}
else
{
AddErrors(result);
}
}
return View(model);
}
和:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
IdentityResult result = await IdentityManager.Authentication.CheckPasswordAndSignInAsync(AuthenticationManager, model.UserName, model.Password, model.RememberMe);
if (result.Success)
{
return Redirect("~/home");
}
else
{
AddErrors(result);
}
}
return View(model);
}
我看到 MVC 代码现在具有异步功能,但有什么区别。一个提供比另一个更好的性能吗?调试一个问题比另一个更容易吗?我应该对其他控制器进行更改以使我的应用程序添加 Async 吗?
【问题讨论】:
-
在绝大多数情况下,在 MVC 中使用异步并没有什么好处,但是也有很多负面影响
-
@ChrisMarisic - 最严重的问题之一:您不能使用 ReaderWriterLock 或任何其他同步原语(Semaphore 除外)。
标签: asp.net-mvc task-parallel-library async-await asp.net-mvc-5 asp.net-identity