public ActionResult LogOn(LogOnModel model, string returnUrl) { try { if (ModelState.IsValid) { var owner = RavenSession.Query<Owner>().SingleOrDefault(x => x.UserName == model.UserName && x.Password == model.Password); if (owner != null) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home", new { language = "en" }); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } } catch (WebException ex) { ModelState.AddModelError("", "Network error while connecting to the database"); } // If we got this far, something failed, redisplay form return View(model); }