La méthode d’action asynchrone MVC4 .NET 4.5 ne redirige pas

J’essaie d’implémenter une méthode d’action de tâche dans mon application MVC 4. Tout fonctionne à l’arrière, mais il ne s’agit pas d’une redirection.

public class AccountController : AsyncController { [HttpPost] [AllowAnonymous] public async Task Login(LoginModel model, ssortingng returnUrl) { var client = new ClientHelper("login"); account = await client.CallActionType(EnumHelpers.HttpType.Post, model); if (account != null) { validLogin = true; } return Redirect(returnUrl); // This is called but the page does not redirect, just sits a load } } 

Je pouvais le faire fonctionner après avoir réalisé l’action. Je le dirigeais également vers une action asynchrone. Je suppose que si vous avez une méthode d’action asynchrone redirigée vers une autre, cette redirection doit également être asynchrone.

Voici juste un exemple rapide

 public async Task Login(LoginModel model) { //You would do some async work here like I was doing. return RedirectToAction("Action","Controller");//The action must be async as well } public async Task Action() {//This must be an async task return View(); } 
 [Authorize] public class AccountController : Controller { [AllowAnonymous] public ActionResult Login(ssortingng returnUrl) { ViewBag.ReturnUrl = returnUrl; return View(); } // // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Login(LoginViewModel model, ssortingng returnUrl) { if (ModelState.IsValid) { // find user by username first var user = await UserManager.FindByNameAsync(model.Email); if (user != null) { var validCredentials = await UserManager.FindAsync(model.Email, model.Password); // When a user is lockedout, this check is done to ensure that even if the credentials are valid // the user can not login until the lockout duration has passed if (await UserManager.IsLockedOutAsync(user.Id)) { ModelState.AddModelError("", ssortingng.Format("Invalid credentials. Please try again, or contact support", 60)); } // if user is subject to lockouts and the credentials are invalid // record the failure and check if user is lockedout and display message, otherwise, // display the number of attempts remaining before lockout else if (await UserManager.GetLockoutEnabledAsync(user.Id) && validCredentials == null) { // Record the failure which also may cause the user to be locked out await UserManager.AccessFailedAsync(user.Id); ssortingng message; if (await UserManager.IsLockedOutAsync(user.Id)) { message = ssortingng.Format("Invalid credentials. Please try again, or contact support", 60); } else { int accessFailedCount = await UserManager.GetAccessFailedCountAsync(user.Id); int attemptsLeft = (5 - accessFailedCount); message = ssortingng.Format("Invalid credentials. Please try again, or contact support.", attemptsLeft); } ModelState.AddModelError("", message); } else if (validCredentials == null) { ModelState.AddModelError("", "Invalid credentials. Please try again, or contact support."); } else { await SignInAsync(user, model.RememberMe); // When token is verified correctly, clear the access failed count used for lockout await UserManager.ResetAccessFailedCountAsync(user.Id); return RedirectToLocal(returnUrl); } } else { ModelState.AddModelError("", ssortingng.Format("Invalid credentials. Please try again, or contact support", 60)); } } // If we got this far, something failed, redisplay form return View(model); } [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { // Don't reveal that the user does not exist or is not confirmed //ModelState.AddModelError("", "The user either does not exist or is not confirmed."); return RedirectToAction("ForgotPasswordConfirmation", "Account"); } else { var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { UserId = user.Id, code = code }, protocol: Request.Url.Scheme); ssortingng Data = System.IO.File.ReadAllText(Server.MapPath(@"~/documents/email_password_reset.txt")); AspNetUser oUser = dbPortal.AspNetUsers.Find(user.Id); // can't use ssortingng.format becuase of CSS Data = Data.Replace("{0}", oUser.Name); // user name Data = Data.Replace("{1}", callbackUrl); // URL to click Data = Data.Replace("{2}", DateTime.Now.Year.ToSsortingng()); // copyright year await UserManager.SendEmailAsync(user.Id, "Reset Password", Data); return RedirectToAction("ForgotPasswordConfirmation", "Account"); } } // If we got this far, something failed, redisplay form return View(model); } // // GET: /Account/ForgotPasswordConfirmation [AllowAnonymous] public async Task ForgotPasswordConfirmation() { return View(); } } 

la solution ci-dessus ne fonctionne pas pour moi