I gave up implementing Windows and Forms Authentication mode in the same project, I've encountered infinite login loops, authorization errors and nightmare-ish spaghetti code.
I'm keeping Forms authentication / RoleProvider just as-is but my idea it's triggering Windows authentication inside the HttpPost for the ActionResult Login
, so the user would enter their domain username, press login button, then compare the text input against HttpContext identity, if true prompt Windows Authentication and if the login is successfull then redirect to admin/user corresponding webpages (getting the role from a SQL table).
This is a vague idea i pseudo coded.
[HttpPost]
public ActionResult Login (usuario u, string retornaUrl) {
string userDomWin = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name.ToString ().Substring ((HttpContext.User.Identity.Name.ToString ().IndexOf ("\\")) + 1);
string userWin = userDomWin.Replace ("DOMAIN\\", "");
var usuarioSys = (from d in db.usuario where d.usuarioDom == userWin select d.usuarioDom).FirstOrDefault ();
if (usuarioSys != null) {
//TRIGGER WINDOWS AUTH
if (WINDOWSAUTH == true) {
Session["uname"] = usuarioSys.ToString ();
if (usuarioSys != null) {
return Redirect ("~/Home/Index");
} else {
TempData["Message"] = "FINISHED.";
return Redirect ("~/Account/Login");
}
} else {
TempData["Message"] = "UNAUTOHRIZED.";
return Redirect ("~/Account/Login");
}
}
return View ();
}
Can you implement something equivalent?