public ActionResult LogOn(LogOnModel model, string returnUrl) { ViewBag.Tema = Settings.Default.Tema; cookie = new HttpCookie("usuario"); if (ModelState.IsValid) { String senha = Crypt.CriptografaM(model.Password); ecomm_clientes result = clientes.getLogin(model.UserName, senha); if (result != null) { FormsAuthentication.SetAuthCookie(result.nome, model.RememberMe); //String usuario = Crypt.Crypter(result.codigo); String usuario = result.codigo; if (Request.Cookies["usuario"] == null) { cookie.Expires = DateTime.Now.AddMinutes(Settings.Default.IntervaloLimpezaCookies); Response.Cookies.Add(cookie); } cookie.Values.Add(usuario, null); Response.Cookies.Add(cookie); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { ViewBag.Tema = Settings.Default.Tema; return(Redirect(returnUrl)); } else { ViewBag.Tema = Settings.Default.Tema; return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Nome de usuário e/ou senha inválidos"); } } return(View(model)); }