Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I'm implementing MVC identity mechanism in my current project, i wanted to redirect the user to Home page or website after successful login, i'm stuck up in the code kindly suggest.

C#
[HttpPost]
       [AllowAnonymous]
       [ValidateAntiForgeryToken]
       public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
       {
           returnUrl = "www.google.com";
           if (!ModelState.IsValid)
           {
               return View(model);
           }

           // This doesn't count login failures towards account lockout
           // To enable password failures to trigger account lockout, change to shouldLockout: true
           //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);
           var result = await SignInManager.PasswordSignInAsync(model.StoreNumber, model.UserName, model.Password, model.RememberMe, shouldLockout: true);
           switch (result)
           {
               case MolSignInStatus.Success:
                   return RedirectToLocal(returnUrl);
               case MolSignInStatus.SucceededAsLegacyUser:
                   // TODO: set certain properties, display warning popup message that user has signed on using legacy credentials.
                   return RedirectToLocal(returnUrl);
               case MolSignInStatus.LockedOut:
                   return View("Lockout");
               case MolSignInStatus.RequiresVerification:
                   return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
               case MolSignInStatus.Failure:
               default:
                   ModelState.AddModelError("", "Invalid login attempt.");
                   return View(model);
           }
       }

C#
private ActionResult RedirectToLocal(string returnUrl)
      {
          if (Url.IsLocalUrl(returnUrl))
          {
              return Redirect(returnUrl);
          }
          return Redirect(returnUrl);
      }


I'm getting resul value as success but it is not redirecting to google.com

What I have tried:

I haave tried with the below line of code trying to redirect to Google website
return Redirect(returnUrl);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900