/// <summary> /// 文档页 /// </summary> /// <param name="tag"></param> /// <param name="id"></param> /// <returns></returns> public void Archive(string lang, string allhtml) { string id = null; string html = String.Empty; Archive archive = null; Category category = null; Regex paramRegex = new Regex("/*([^/]+).html$", RegexOptions.IgnoreCase); if (paramRegex.IsMatch(allhtml)) { id = paramRegex.Match(allhtml).Groups[1].Value; archive = bll.Get(id); } if (archive == null) { base.RenderNotfound(); return; } else { BuiltInArchiveFlags flag = ArchiveFlag.GetBuiltInFlags(archive.Flags); if ((flag & BuiltInArchiveFlags.Visible) != BuiltInArchiveFlags.Visible) //|| (flag & BuiltInArchiveFlags.IsSystem) == BuiltInArchiveFlags.IsSystem) { base.RenderNotfound(); return; } category = cbll.Get(a => a.ID == archive.Cid); if (category == null) { base.RenderNotfound(); return; } else { string vpath = "/" + lang; if ((flag & BuiltInArchiveFlags.AsPage) == BuiltInArchiveFlags.AsPage) { string pattern = "^" + vpath + "/[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$"; string pagePattern = "^" + vpath + "/[\\.0-9A-Za-z_-]+\\.html$"; if (!Regex.IsMatch(Request.Path, pagePattern)) { Response.StatusCode = 301; Response.RedirectLocation = String.Format("/{0}/{1}.html", lang, String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias ); Response.End(); return; } } else { //校验栏目是否正确 string categoryPath = ArchiveUtility.GetCategoryUrlPath(category); if (!allhtml.StartsWith(categoryPath + "/")) { base.RenderNotfound(); return; } //设置了别名,则跳转 if (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, true) != 0) //设置了别名 { Response.StatusCode = 301; Response.RedirectLocation = String.Format("/{0}/{1}/{2}.html", lang, category.Tag, String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias ); Response.End(); return; } } //增加浏览次数 ++archive.ViewCount; new System.Threading.Thread(() => { try { bll.AddViewCount(archive.ID, 1); } catch { } }).Start(); //显示页面 html = cmsPage.GetArchive(category, archive, lang); //再次处理模板 //html = PageUtility.Render(html, new { }, false); } } base.Render(html); }
/// <summary> /// 访问文档 /// </summary> /// <param name="context"></param> /// <param name="allhtml"></param> public static void RenderArchive(CmsContext context, string allhtml) { string id = null; string html; ArchiveDto archive = default(ArchiveDto); //检测网站状态 if (!context.CheckSiteState()) { return; } //检查缓存 if (!context.CheckAndSetClientCache()) { return; } var siteId = context.CurrentSite.SiteId; ICmsPageGenerator cmsPage = new PageGeneratorObject(context); Regex paramRegex = new Regex("/*([^/]+).html$", RegexOptions.IgnoreCase); if (paramRegex.IsMatch(allhtml)) { id = paramRegex.Match(allhtml).Groups[1].Value; archive = ServiceCall.Instance.ArchiveService.GetArchiveByIdOrAlias(siteId, id); } if (archive.Id <= 0) { RenderNotFound(context); return; } else { //跳转 if (!String.IsNullOrEmpty(archive.Location)) { string url; if (Regex.IsMatch(archive.Location, "^http://", RegexOptions.IgnoreCase)) { url = archive.Location; } else { if (archive.Location.StartsWith("/")) { throw new Exception("URL不能以\"/\"开头!"); } url = String.Concat(context.SiteDomain, "/", archive.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>"); return; } BuiltInArchiveFlags flag = ArchiveFlag.GetBuiltInFlags(archive.Flags); if ((flag & BuiltInArchiveFlags.Visible) != BuiltInArchiveFlags.Visible) //|| (flag & BuiltInArchiveFlags.IsSystem)== BuiltInArchiveFlags.IsSystem) //系统文档可以单独显示 { RenderNotFound(context); return; } CategoryDto category = archive.Category; if (!(category.Id > 0)) { RenderNotFound(context); return; } else { string appPath = AtNet.Cms.Cms.Context.SiteAppPath; if (appPath != "/") { appPath += "/"; } if ((flag & BuiltInArchiveFlags.AsPage) == BuiltInArchiveFlags.AsPage) { string pattern = "^" + appPath + "[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$"; string pagePattern = "^" + appPath + "[\\.0-9A-Za-z_-]+\\.html$"; if (!Regex.IsMatch(context.Request.Path, pagePattern)) { context.Response.StatusCode = 301; context.Response.RedirectLocation = String.Format("{0}{1}.html", appPath, String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias ); context.Response.End(); return; } } else { //校验栏目是否正确 string categoryPath = category.UriPath; string _path = appPath != "/" ? allhtml.Substring(appPath.Length - 1) : allhtml; if (!_path.StartsWith(categoryPath + "/")) { RenderNotFound(context); return; } //设置了别名,则跳转 if (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, true) != 0) { context.Response.StatusCode = 301; context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html", appPath, categoryPath, String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias ); context.Response.End(); return; } } //增加浏览次数 ++archive.ViewCount; new System.Threading.Thread(() => { try { ServiceCall.Instance.ArchiveService.AddCountForArchive(siteId, archive.Id, 1); } catch { } }).Start(); //显示页面 html = cmsPage.GetArchive(archive); //再次处理模板 //html = PageUtility.Render(html, new { }, false); } } // return html; context.Render(html); }
/// <summary> /// 访问文档 /// </summary> /// <param name="context"></param> /// <param name="allhtml"></param> public static void RenderArchive(CmsContext context, string allhtml) { string html; ArchiveDto archive = default(ArchiveDto); //检测网站状态 if (!context.CheckSiteState()) { return; } //检查缓存 if (!context.CheckAndSetClientCache()) { return; } var siteId = context.CurrentSite.SiteId; String archivePath = allhtml.Substring(0, allhtml.Length - ".html".Length); archive = ServiceCall.Instance.ArchiveService.GetArchiveByIdOrAlias(siteId, archivePath); if (archive.Id <= 0) { RenderNotFound(context); return; } // 如果设置了302跳转 if (!String.IsNullOrEmpty(archive.Location)) { string url; if (Regex.IsMatch(archive.Location, "^http://", RegexOptions.IgnoreCase)) { url = archive.Location; } else { if (archive.Location.StartsWith("/")) { throw new Exception("URL不能以\"/\"开头!"); } url = String.Concat(context.SiteDomain, "/", archive.Location); } context.Response.Redirect(url, true); //302 return; } ICmsPageGenerator cmsPage = new PageGeneratorObject(context); BuiltInArchiveFlags flag = ArchiveFlag.GetBuiltInFlags(archive.Flags); if ((flag & BuiltInArchiveFlags.Visible) != BuiltInArchiveFlags.Visible) //|| (flag & BuiltInArchiveFlags.IsSystem)== BuiltInArchiveFlags.IsSystem) //系统文档可以单独显示 { RenderNotFound(context); return; } CategoryDto category = archive.Category; if (!(category.ID > 0)) { RenderNotFound(context); return; } else { string appPath = Cms.Context.SiteAppPath; if (appPath != "/") { appPath += "/"; } if ((flag & BuiltInArchiveFlags.AsPage) == BuiltInArchiveFlags.AsPage) { string pattern = "^" + appPath + "[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$"; string pagePattern = "^" + appPath + "[\\.0-9A-Za-z_-]+\\.html$"; if (!Regex.IsMatch(context.Request.Path, pagePattern)) { context.Response.StatusCode = 301; context.Response.RedirectLocation = String.Format("{0}{1}.html", appPath, String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias ); context.Response.End(); return; } } else { //校验栏目是否正确 string categoryPath = category.Path; string path = appPath != "/" ? allhtml.Substring(appPath.Length - 1) : allhtml; if (!path.StartsWith(categoryPath + "/")) { RenderNotFound(context); return; } /* * //设置了别名,则跳转 * if (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, * StringComparison.OrdinalIgnoreCase) != 0) * { * context.Response.StatusCode = 301; * context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html", * appPath, * categoryPath, * String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias * ); * context.Response.End(); * return; * } */ } //增加浏览次数 ++archive.ViewCount; ServiceCall.Instance.ArchiveService.AddCountForArchive(siteId, archive.Id, 1); //显示页面 html = cmsPage.GetArchive(archive); //再次处理模板 //html = PageUtility.Render(html, new { }, false); } // return html; context.Render(html); }