protected void RenderTemplateUseCache(string content, object dataObj) { if (!AtNet.Cms.Cms.Cache.CheckClientCacheExpiresByEtag()) { return; } string html = null; HttpResponse response = this.Response; MicroTemplateEngine _tpl = new MicroTemplateEngine(tpl); html = _tpl.Execute(content); if (dataObj != null) { //替换传入的标签参数 PropertyInfo[] properties = dataObj.GetType().GetProperties(); object dataValue; foreach (PropertyInfo p in properties) { dataValue = p.GetValue(dataObj, null); if (dataValue != null) html = ReplaceHtml(html, p.Name, dataValue.ToString()); } } if (!Array.Exists(ignoreURI, a => HttpContext.Current.Request.Url.Query.IndexOf(a) != -1)) { html = CompressHtml(html); } setHeader: //设置缓存 AtNet.Cms.Cms.Cache.SetClientCacheByEtag(this.Response); //输出内容 this.Response.Write(html); if (Settings.Opti_SupportGZip) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); response.AddHeader("Content-Encoding", "gzip"); } response.AddHeader("X-AspNet-Version", String.Format("AtNet.Cms v{0}", AtNet.Cms.Cms.Version)); response.AddHeader("Support-URL", "www.ops.cc/cms/"); }
protected void RenderTemplate(string content, object dataObj) { string html = null; HttpResponse response = this.Response; MicroTemplateEngine _tpl = new MicroTemplateEngine(tpl); html = _tpl.Execute(content); if (dataObj != null) { //替换传入的标签参数 PropertyInfo[] properties = dataObj.GetType().GetProperties(); object dataValue; foreach (PropertyInfo p in properties) { dataValue = p.GetValue(dataObj, null); if (dataValue != null) html = ReplaceHtml(html, p.Name, dataValue.ToString()); } } if (!Array.Exists(ignoreURI, a => HttpContext.Current.Request.Url.Query.IndexOf(a) !=-1)) { html = CompressHtml(html); } if (this.Request["ajax"] == "1" || HttpContext.Current.Items["ajax"] == "1") { const string ajaxPartern = "<body([^>]*)>([\\s\\S]+)</body>"; if (Regex.IsMatch(html, ajaxPartern)) { Match match = Regex.Match(html, ajaxPartern); response.Write(match.Groups[2].Value); goto setHeader; } } //输出内容 response.Write(html); setHeader: if (Settings.Opti_SupportGZip) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); response.AddHeader("Content-Encoding", "gzip"); } }