0
[AllowAnonymous]
public class AuthController : Controller
{

    [HttpGet]
    public ActionResult Login(string returnUrl)
    {
        ViewBag.ReturnUrl = returnUrl;

       return View();

    }


    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Login(LoginViewModel model)
    {
        if (ModelState.IsValid)
        {
            PartialLogin login = new PartialLogin();


            if ((model.BusinessEmail != null && model.BusinessPassword != null) ||
                (model.InvestorEmail != null && model.InvestorPassword != null))
            {

                if (login.ValidateBusinessLogin(model.BusinessEmail, model.BusinessPassword))
                {
                    FormsAuthentication.SetAuthCookie(model.InvestorEmail, true);

                    Session["BusinessUserEmail"] = model.InvestorEmail;


                    return RedirectToAction("Index", "Business");
                }

                //if (login.ValidateInvestorLogin(model.InvestorEmail, model.InvestorPassword))
                //{
                if (model.InvestorEmail == "mahamQ@gmail.com")
                {
                   FormsAuthentication.SetAuthCookie(model.InvestorEmail, true);

                    Session["InvestorUserEmail"] = model.InvestorEmail;

                    return RedirectToAction("Index", "Investor");
                }
            }
            else
            {
                return RedirectToAction("Login", "Auth");
            }

        }

            return View();


    }

}

My original after clicking on Login on index page the url is Localhost/WebappCustom/Auth/Login, however after submitting the form, the url becomes as shown in the image and stays on the same login page rather than changing to localhost/WebAppCustom/Investor/Index

enter image description here

Tasos K.
  • 7,979
  • 7
  • 39
  • 63
m.tan
  • 1
  • Which return statement gets executed when you post your login form? I see there are 3 return statements in your Login action – User3250 May 13 '17 at 13:24
  • it comes correctly to the return redirectToAction("Index", "Investor") when i enter my email as "mahamQ@gmail.com" and then it jumps to the HttpGet Login method and when that method executes, it shows in the url as i've shown in the posted picture and stays on the Login page instead of going to the Index action of the other controller – m.tan May 13 '17 at 13:32
  • My login page has two forms using the same viewModel – m.tan May 13 '17 at 13:33
  • Seems your Auth is not working [see here](http://stackoverflow.com/a/7217957/4868839) – User3250 May 13 '17 at 14:15
  • can you please elaborate the error? :/ – m.tan May 13 '17 at 14:31
  • FormsAuthentication.SetAuthCookie(model.InvestorEmail, true); isn't working hence actually you are not logging into app. To login and goto next page you need login first. Use Formsauthentication code as I mentioned in the url and then try logging in – User3250 May 13 '17 at 14:59

0 Answers0