/// <summary> /// Verifica la información en Cache /// </summary> /// <param name="key"></param> /// <param name="idPais"></param> private static void CheckCache(String key, int idPais) { try { if (System.Web.HttpContext.Current.Cache.Get(key) == null) { UsrCache.AddPagesToCache(key, GetDataCache(key, idPais), System.Web.HttpContext.Current); } } catch (Exception) { //log.Error(ex); } }
protected void btnLogin_Click(object sender, EventArgs e) { if (Page.IsValid) { IUsr Usr = new Usr(txtUsuario.Text.ToLower(), txtPass.Text, Int32.Parse(ddlPa.SelectedValue)); if (Usr.usr != null & Usr.IsAuth()) { if (Usr.IsActive()) { if (Usr.usr.Rol != null) { UsrCache.AddPagesToCache(Usr.usr.CemexId, Usr.GetDataCache(), HttpContext.Current); var authTicket = new FormsAuthenticationTicket(2, Usr.usr.CemexId, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, Usr.usr.Pais.IdPais.ToString(), FormsAuthentication.FormsCookiePath); String crypTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, crypTicket); //authCookie.Expires = DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes); Response.Cookies.Add(authCookie); Session["Usr"] = Usr; Response.Redirect("~" + Usr.DefaultPage()); } else { lblError.Text = "El usuario no tiene asignado un Rol valido"; lblError.Visible = true; } } else { lblError.Text = "Usuario Inactivo"; lblError.Visible = true; } } else { lblError.Text = "Usuario o Contraseña Incorrecto"; lblError.Visible = true; } } }
/// <summary> /// Administra la autorización por Request /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AuthorizeRequest(object sender, EventArgs e) { var lt = new List <String>() { "/Account/", "/Images/", "/Scripts/", ".axd", ".ashx", ".css", ".asmx" }; if (((IObjCache)System.Web.HttpContext.Current.Cache.Get("Lpg")) == null) { List <IPagePTO> pg = new List <IPagePTO>(); pg.Add(Usr.LPage()); UsrCache.AddPagesToCache("Lpg", new ObjCache(pg, null), HttpContext.Current); } if (lt.Any(r => HttpContext.Current.Request.Path.ToLower().Contains(r.ToLower()))) { return; } //if (HttpContext.Current.Request.Path.ToLower().Contains("/account/")) //{ // return; //} if (HttpContext.Current.User != null) { //Si el usuario esta Autenticado if (HttpContext.Current.User.Identity.IsAuthenticated) { if (HttpContext.Current.User is FPrincipal) { FPrincipal principal = (FPrincipal)HttpContext.Current.User; if (!principal.IsPageEnabled(HttpContext.Current.Request.Path)) { HttpContext.Current.Server.Transfer("~/Account/AuthE.aspx"); } } } } }