protected void RenderTemplate(string content, object dataObj) { string html = null; var response = Response; var _tpl = new MicroTemplateEngine(tpl); html = _tpl.Execute(content); if (dataObj != null) { //替换传入的标签参数 var properties = dataObj.GetType().GetProperties(); object dataValue; foreach (var p in properties) { dataValue = p.GetValue(dataObj, null); if (dataValue != null) { html = ReplaceHtml(html, p.Name, dataValue.ToString()); } } } var query = Request.GetQueryString(); if (!Array.Exists(ignoreURI, a => query.IndexOf(a, StringComparison.Ordinal) != -1)) { html = CompressHtml(html); } HttpHosting.Context.TryGetItem <string>("ajax", out var isAjax); if (Request.Query("ajax") == "1" || isAjax == "1") { const string ajaxPartern = "<body([^>]*)>([\\s\\S]+)</body>"; if (Regex.IsMatch(html, ajaxPartern)) { var match = Regex.Match(html, ajaxPartern); response.WriteAsync(match.Groups[2].Value); return; //goto setHeader; } } //输出内容 response.WriteAsync(html); // setHeader: // // if (Settings.Opti_SupportGZip) // { // response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); // response.AddHeader("Content-Encoding", "gzip"); // } }
protected void RenderTemplateUseCache(string content, object dataObj) { if (!Cms.Cache.CheckClientCacheExpiresByEtag()) { return; } string html = null; var response = Response; var _tpl = new MicroTemplateEngine(tpl); html = _tpl.Execute(content); if (dataObj != null) { //替换传入的标签参数 var properties = dataObj.GetType().GetProperties(); object dataValue; foreach (var p in properties) { dataValue = p.GetValue(dataObj, null); if (dataValue != null) { html = ReplaceHtml(html, p.Name, dataValue.ToString()); } } } var query = HttpHosting.Context.Request.GetQueryString(); if (!Array.Exists(ignoreURI, a => query.IndexOf(a) != -1)) { html = CompressHtml(html); } setHeader: //设置缓存 Cms.Cache.SetClientCacheByEtag(Response); response.ContentType("text/html;charset=utf-8"); //输出内容 Response.WriteAsync(html); //todo: gzip // if (Settings.Opti_SupportGZip) // { // response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); // response.AddHeader("Content-Encoding", "gzip"); // } // // response.AddHeader("X-AspNet-Version", String.Format("jr.Cms v{0}", Cms.Version)); // response.AddHeader("Support-URL", "cms.to2.net/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.StartsWith(a, true, System.Globalization.CultureInfo.CurrentCulture))) { 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"); } }
protected void RenderTemplateUseCache(string content, object dataObj) { if (!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.StartsWith(a, true, System.Globalization.CultureInfo.CurrentCulture))) { html = CompressHtml(html); } setHeader: //设置缓存 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("Ops.Cms v{0}", Cms.Version)); response.AddHeader("Support-URL", "www.ops.cc/cms/"); }
protected string RequireTemplate(string content) { string html = null; var response = Response; var _tpl = new MicroTemplateEngine(tpl); html = _tpl.Execute(content); object value; foreach (var p in ViewData.Keys) { if ((value = ViewData[p]) != null) { html = ReplaceHtml(html, p.ToString(), value.ToString()); } } var query = Request.GetQueryString(); if (!Array.Exists(ignoreURI, a => query.IndexOf(a, StringComparison.Ordinal) != -1)) { html = CompressHtml(html); } // if (Settings.Opti_SupportGZip) // { // response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); // response.AddHeader("Content-Encoding", "gzip"); // } HttpHosting.Context.TryGetItem <string>("ajax", out var isAjax); if (Request.Query("ajax") == "1" || isAjax == "1") { const string ajaxPattern = "<body([^>]*)>([\\s\\S]+)</body>"; if (Regex.IsMatch(html, ajaxPattern)) { var match = Regex.Match(html, ajaxPattern); return(match.Groups[2].Value); } } return(html); }
protected string RequireTemplate(string content) { string html = null; HttpResponse response = this.Response; MicroTemplateEngine _tpl = new MicroTemplateEngine(tpl); html = _tpl.Execute(content); object value; foreach (object p in this.ViewData.Keys) { if ((value = this.ViewData[p]) != null) { html = ReplaceHtml(html, p.ToString(), value.ToString()); } } if (!Array.Exists(ignoreURI, a => HttpContext.Current.Request.Url.Query.IndexOf(a) != -1)) { html = CompressHtml(html); } if (Settings.Opti_SupportGZip) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); response.AddHeader("Content-Encoding", "gzip"); } 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); return(match.Groups[2].Value); } } return(html); }
protected void RenderTemplateUseCache(string content, object dataObj) { if (!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.StartsWith(a, true, System.Globalization.CultureInfo.CurrentCulture))) { html = CompressHtml(html); } setHeader: //设置缓存 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("Ops.Cms v{0}", 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.StartsWith(a, true, System.Globalization.CultureInfo.CurrentCulture))) { 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"); } }