/// <summary> /// 呈现分类页 /// </summary> /// <param name="context"></param> /// <param name="allcate"></param> public static void RenderCategory(CmsContext context, string tag, int page) { //检查缓存 if (!context.CheckAndSetClientCache()) return; int siteId = context.CurrentSite.SiteId; string html = String.Empty; CategoryDto category; string allcate = context.Request.Path.Substring(1); ICmsPageGenerator cmsPage = new PageGeneratorObject(context); category = ServiceCall.Instance.SiteService.GetCategory(siteId, tag); if (!(category.ID>0)) { RenderNotFound(context); return; } //获取路径 string categoryPath = category.UriPath; string appPath = Cms.Context.SiteAppPath; string _path = appPath != "/" ? allcate.Substring(appPath.Length) : allcate; if (!_path.StartsWith(categoryPath)) { RenderNotFound(context); return; } /********************************* * @ 单页,跳到第一个特殊文档, * @ 如果未设置则最新创建的文档, * @ 如未添加文档则返回404 *********************************/ if (String.IsNullOrEmpty(category.Location)) { html = cmsPage.GetCategory(category, page); context.Render(html); } else { string url; if (Regex.IsMatch(category.Location, "^http://", RegexOptions.IgnoreCase)) { url = category.Location; } else { if (category.Location.StartsWith("/")) throw new Exception("URL不能以\"/\"开头!"); url = String.Concat(context.SiteDomain, category.Location); /* if (category.Location.StartsWith("/")) throw new Exception("URL不能以\"/\"开头!"); string url=String.Concat(context.SiteDomain,category.Location); try { string temphtml = new WebClient().DownloadString(url); context.Render(temphtml); } catch(Exception exc) { context.Render("<span style='color:red'>定向到指定页面时报错,请打开<a href='" + url + "'>" + url + "</a>查看详情!</span>"); } context.HttpContext.Response.End(); */ } context.Render(@"<html><head><meta name=""robots"" content=""noindex""><script>location.href='" + url + "';</script></head><body></body></html>"); /* ArchiveDto a = ServiceCall.Instance.ArchiveService.GetSpecialArchives(siteId, category.Tag, 1).SingleOrDefault()?? ServiceCall.Instance.ArchiveService.GetArchivesByCategoryTag(siteId, category.Tag, 1).SingleOrDefault(); if (a == null) { RenderNotFound(context); return; } context.Response.StatusCode = 302; context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html", appPath == "/" ? appPath : appPath + "/", categoryPath, String.IsNullOrEmpty(a.Alias) ? a.ID : a.Alias ); context.Response.End(); return; */ } }
/// <summary> /// 呈现分类页 /// </summary> /// <param name="context"></param> /// <param name="allcate"></param> public static void RenderCategory(CmsContext context, string tag, int page) { //检查缓存 if (!context.CheckAndSetClientCache()) { return; } int siteId = context.CurrentSite.SiteId; string html = String.Empty; CategoryDto category; string allcate = context.Request.Path.Substring(1); ICmsPageGenerator cmsPage = new PageGeneratorObject(context); category = ServiceCall.Instance.SiteService.GetCategory(siteId, tag); if (!(category.Id > 0)) { RenderNotFound(context); return; } //获取路径 string categoryPath = category.UriPath; string appPath = Cms.Context.SiteAppPath; string _path = appPath != "/" ? allcate.Substring(appPath.Length) : allcate; if (!_path.StartsWith(categoryPath)) { RenderNotFound(context); return; } /********************************* * @ 单页,跳到第一个特殊文档, * @ 如果未设置则最新创建的文档, * @ 如未添加文档则返回404 *********************************/ if (String.IsNullOrEmpty(category.Location)) { html = cmsPage.GetCategory(category, page); context.Render(html); } else { string url; if (Regex.IsMatch(category.Location, "^http://", RegexOptions.IgnoreCase)) { url = category.Location; } else { if (category.Location.StartsWith("/")) { throw new Exception("URL不能以\"/\"开头!"); } url = String.Concat(context.SiteDomain, category.Location); } context.Response.Redirect(url, true); //302 //context.Response.StatusCode = 301; //context.Render(@"<html><head><meta name=""robots"" content=""noindex""><script>location.href='" + // url + "';</script></head><body></body></html>"); } }
/// <summary> /// 呈现分类页 /// </summary> /// <param name="context"></param> /// <param name="allcate"></param> public static void RenderCategory(CmsContext context, string tag, int page) { //检查缓存 if (!context.CheckAndSetClientCache()) { return; } int siteId = context.CurrentSite.SiteId; string html = String.Empty; CategoryDto category; string allcate = context.Request.Path.Substring(1); ICmsPageGenerator cmsPage = new PageGeneratorObject(context); category = ServiceCall.Instance.SiteService.GetCategory(siteId, tag); if (!(category.ID > 0)) { RenderNotFound(context); return; } //获取路径 string categoryPath = category.UriPath; string appPath = Cms.Context.SiteAppPath; string _path = appPath != "/" ? allcate.Substring(appPath.Length) : allcate; if (!_path.StartsWith(categoryPath)) { RenderNotFound(context); return; } /********************************* * @ 单页,跳到第一个特殊文档, * @ 如果未设置则最新创建的文档, * @ 如未添加文档则返回404 *********************************/ if (String.IsNullOrEmpty(category.Location)) { html = cmsPage.GetCategory(category, page); context.Render(html); } else { string url; if (Regex.IsMatch(category.Location, "^http://", RegexOptions.IgnoreCase)) { url = category.Location; } else { if (category.Location.StartsWith("/")) { throw new Exception("URL不能以\"/\"开头!"); } url = String.Concat(context.SiteDomain, category.Location); /* * if (category.Location.StartsWith("/")) throw new Exception("URL不能以\"/\"开头!"); * string url=String.Concat(context.SiteDomain,category.Location); * * try * { * string temphtml = new WebClient().DownloadString(url); * context.Render(temphtml); * } * catch(Exception exc) * { * context.Render("<span style='color:red'>定向到指定页面时报错,请打开<a href='" + * url + "'>" + url + "</a>查看详情!</span>"); * } * * context.HttpContext.Response.End(); */ } context.Render(@"<html><head><meta name=""robots"" content=""noindex""><script>location.href='" + url + "';</script></head><body></body></html>"); /* * ArchiveDto a = ServiceCall.Instance.ArchiveService.GetSpecialArchives(siteId, category.Tag, 1).SingleOrDefault()?? * ServiceCall.Instance.ArchiveService.GetArchivesByCategoryTag(siteId, category.Tag, 1).SingleOrDefault(); * * if (a == null) * { * RenderNotFound(context); * return; * } * context.Response.StatusCode = 302; * context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html", * appPath == "/" ? appPath : appPath + "/", * categoryPath, * String.IsNullOrEmpty(a.Alias) ? a.ID : a.Alias * ); * context.Response.End(); * return; */ } }