public ActionResult LogOn(AccountLogOnModel model) { if (ModelState.IsValid) { #region Authenticator AuthenticatorManager authenticatorManager = new AuthenticatorManager(); Authenticator authenticator = authenticatorManager.GetAuthenticatorById(model.AuthenticatorList.Id); Assembly assembly = Assembly.Load(authenticator.AssemblyPath); Type type = assembly.GetType(authenticator.ClassPath); #endregion Authenticator #region AuthenticationManager IAuthenticationManager authenticationManager = (IAuthenticationManager)Activator.CreateInstance(type, authenticator.ConnectionString); #endregion AuthenticationManager if (authenticationManager.ValidateUser(model.Username, model.Password)) { SubjectManager subjectManager = new SubjectManager(); if (!subjectManager.ExistsUsernameWithAuthenticatorId(model.Username, model.AuthenticatorList.Id)) { subjectManager.CreateUser(model.Username, model.AuthenticatorList.Id); } FormsAuthentication.SetAuthCookie(model.Username, false); return Json(new { success = true }); } else { ModelState.AddModelError("", "The Username or Password provided is incorrect."); } } return PartialView("_LogOnPartial", model); }
public string RenderRazorViewToString() { Controller controller = this; string viewName = "_LogOnPartial"; AccountLogOnModel model = new AccountLogOnModel(); controller.ViewData.Model = model; using (var sw = new StringWriter()) { var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName); var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw); viewResult.View.Render(viewContext, sw); viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View); return sw.GetStringBuilder().ToString(); } }