public static IHtmlString Widget <T>(this HtmlHelper html, string url, WidgetBag <T> bag) where T : class { var request = html.ViewContext.HttpContext.Request; Uri referer = request.UrlReferrer ?? request.Url; string content = HttpHelper.Post <WidgetBag <T> >(url, bag, null, request.UserAgent, referer, LocaleHelper.Localizer.GetCurrentCultureInfo()); return(new HtmlString(content)); }
public static IHtmlString CacheWidget <T>(this HtmlHelper html, string key, int cacheSeconds, string url, WidgetBag <T> bag, bool isSessionCache = false) where T : class { #if !DEBUG var cacheManager = WebHelper.GetService <ICacheManager>(); ICacheProvider cache = null; if (isSessionCache) { cache = cacheManager.CreateCacheProvider(CacheScope.WorkUnit); } else { cache = cacheManager.CreateCacheProvider(CacheScope.Global); } if (cacheSeconds > 0 && !string.IsNullOrWhiteSpace(key) && cache != null) { IHtmlString content = null; content = cache.GetData(key) as IHtmlString; if (content != null) { return(content); } content = html.Widget <T>(url, bag); cache.Add(key, content, null, new TimeSpan(0, 0, cacheSeconds), DateTime.MaxValue); return(content); } #endif return(html.Widget <T>(url, bag)); }