public static IEnumerable <ItemMenu> GetMenu(this HtmlHelper helper) { var menuJson = HttpContext.Current.Session["mainMenu"] as string; if (string.IsNullOrWhiteSpace(menuJson)) { HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie == null) { return(null); } FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); var usuario = JsonConvert.DeserializeObject <dynamic>(ticket.UserData); var token = usuario.Token.ToString(); menuJson = GeoToken.GetMenuJson(token); HttpContext.Current.Session["mainMenu"] = menuJson; } if (string.IsNullOrWhiteSpace(menuJson)) { HttpContext.Current.Response.RedirectLocation = "http://google.com.pe"; } var menus = JsonConvert.DeserializeObject <IEnumerable <ItemMenu> >(menuJson); return(menus); }
public static bool IsValidMenu(this HtmlHelper helper) { var menuJson = HttpContext.Current.Session["mainMenu"] as string; if (string.IsNullOrWhiteSpace(menuJson)) { HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie == null) { return(false); } FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); var usuario = JsonConvert.DeserializeObject <dynamic>(ticket.UserData); var token = usuario.Token.ToString(); menuJson = GeoToken.GetMenuJson(token); HttpContext.Current.Session["mainMenu"] = menuJson; } return(!string.IsNullOrWhiteSpace(menuJson) && !menuJson.Contains("errorDescription")); }