Wednesday, 11 September 2013

MVC log in is not working

MVC log in is not working

I have a MVC3 application, n my log in module works fine when I run the
solution from VS. But when I added it as a site in my IIS(ver 6) The log
in is not working. I wrote to a txt file to see whether log in fails, but
log in is successful. But it does not let me to go to the home page it
directs me back to log in page itself. please help.
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl) {
string lines = "UserName:" + model.Username + " Pwd:" +
model.Password + " IsValid:" + ModelState.IsValid + "\n";
System.IO.File.WriteAllText(@"E:\Nirushan.txt", lines);
if (!ModelState.IsValid) {
ModelState.AddModelError("",
GetLocalResource("Message.InvalidLogin"));
return View();
}
var authenticationResult =
_authenticationService.TryAuthenticateDirectLogin(model.Username,
model.Password);
using (System.IO.StreamWriter file = new
System.IO.StreamWriter(@"E:\Nirushan.txt", true))
{
file.WriteLine();
//Status is success
file.WriteLine("Status:" +
authenticationResult.AuthenticationStatus);
bool st =
AuthenticationTicketService.SetAuthenticationTicket(authenticationResult.AuthenticatedUser.Id);
// st is true
file.WriteLine("TicketService:" + st);
}
if (authenticationResult.AuthenticationStatus ==
AuthenticationStatus.RegeneratedForgottenPasswordExpired)
{
ModelState.AddModelError("",
GetLocalResource("Message.RegeneratedForgottenPasswordExpired"));
return View();
}
if (authenticationResult.AuthenticationStatus ==
AuthenticationStatus.UserIsLockedOut) {
ModelState.AddModelError("",
GetLocalResource("Message.UserIsLockedOut"));
return View();
}
if (authenticationResult.AuthenticationStatus ==
AuthenticationStatus.DirectLoginNotAllowed) {
ModelState.AddModelError("",
GetLocalResource("Message.DirectLoginNotAllowed"));
return View();
}
if (authenticationResult.AuthenticationStatus !=
AuthenticationStatus.Success) {
ModelState.AddModelError("",
GetLocalResource("Message.LoginFailed"));
return View();
}
if (authenticationResult.AuthenticatedUser.PasswordChange)
return RedirectToAction("ChangePassword", new {
returnUrl,
model.Username
});
if
(AuthenticationTicketService.SetAuthenticationTicket(authenticationResult.AuthenticatedUser.Id)
== false) {
ModelState.AddModelError("",
GetLocalResource("Message.MissingSessionInfo"));
return View();
}
return Redirect(returnUrl ?? Url.Action("Index", "Home"));
}

No comments:

Post a Comment