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);
EncryptTicketCookies(model);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", Messages.InvalidUidPwd);
}
}
return View(model);
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
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' 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!!!