I have an MVC application, which has two areas - Administrator, and User. What I wanted to do, is on first login, the User will activate their account, agree to terms and conditions, etc. This application uses the asp membership api.
I have inserted an IF statement into the POST login action in the Account controller, however after debugging, it appears that this if statement is never executed. If someone could take a look at it I'd be very grateful. I have a feeling it could be something small I'm missing.
The login URL for the User is:
The administrator URL is:
however both use the same login action in the account controller so hence the need to use an if statement to differentiate between the two.
Here is the code for the POST Logon action. The string returnUrl is "/User" not "User" which I discovered after debugging through the code.
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
string url = returnUrl;
if (url == "/User")
{
ModelContainer ctn = new ModelContainer();
MyApp.Data.User p = ctn.Users.First(t => t.UserID == UserServices.CurrentUserId);
string status = p.AccountStatus;
if (status != "Active")
{
return RedirectToAction("contract", "Home");
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
It just seems to skip after the else here:
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
string url = returnUrl;
and jumps right down to the final RedirectToAction.
I'd be very grateful if anyone could spot anything. If more info is needed just shout!