异步操作方法“Login”返回一个不能同步执行的Task。 [英] The asynchronous action method 'Login' returns a Task, which cannot be executed synchronously.
本文介绍了异步操作方法“Login”返回一个不能同步执行的Task。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在运行时遇到了MVC 5的问题。
错误正在线下。
Hello everyone,
I have facing issues in MVC 5 at the run time.
Error is coming below line.
var rc = new RequestContext( new HttpContextWrapper(Context), routeData);
controller.Execute(rc);
代码详情
Code Details are
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
// Encrypt the ticket and Create the cookie.
EncryptTicketCookies(model);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", Messages.InvalidUidPwd);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
// Get the authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
// If the cookie can't be found, don't issue the ticket, redirect to the login page.
if (authCookie == null)
{
var routeData = new RouteData();
routeData.Values["controller"] = "Account";
routeData.Values["action"] = "Login";
IController controller = null;
controller = new AccountController();
var rc = new RequestContext( new HttpContextWrapper(Context), routeData);
controller.Execute(rc);
}
}
发生System.InvalidOperationException'在System.Web.Mvc.dll中但未在用户代码中处理。
附加信息:异步操作方法'Login'返回一个无法同步执行的任务。
请帮帮我?
提前致谢! !!
System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code.
Additional information: The asynchronous action method 'Login' returns a Task, which cannot be executed synchronously.
Please help me?
Thanks in advance!!!
推荐答案
它可能对你有帮助。
异步操作方法返回一个无法同步执行的任务 [ ^ ]
It might help you.
asynchronous action method returns a Task, which cannot be executed synchronously[^]
这篇关于异步操作方法“Login”返回一个不能同步执行的Task。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文