生成静态html的问题
// 生成静态页
private void GenerateHTML(string titleid)
{
string Bbs_TitleBody = "Bbs_TitleBody_" + titleid.ToString();//缓存名,以分类Id为参数
Cache.Remove(Bbs_TitleBody);
DataTable dt = BbsCache.Bbs_GetTitleById(int.Parse(titleid));
// Response.Write(dt.Rows[0]["title"].ToString());
string fileyyyymmdd = dt.Rows[0]["fileyyyymmdd"].ToString();
string filename = fileyyyymmdd + titleid + ".html";
string caid = dt.Rows[0]["caid"].ToString();
string caname = ddlXL.SelectedItem.Text;
string title = dt.Rows[0]["title"].ToString();
string content = dt.Rows[0]["body"].ToString();
string time = DateTime.Parse(dt.Rows[0]["createdate"].ToString()).ToShortDateString();
string username = dt.Rows[0]["username"].ToString();
string sourceurl = "/forum/Show.aspx?TitleId=" + titleid + "&CaId=" + caid;
#region 生成静态页
//创建当前日期的文件夹开始
string dir = Server.MapPath("~/" + "ITNews/" + fileyyyymmdd);//用来生成文件夹
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
//创建当前日期的文件夹结束
try
{
StringBuilder strhtml = new StringBuilder();
//创建StreamReader对象
using (StreamReader sr = new StreamReader(Server.MapPath("template.htm"), System.Text.Encoding.Default))
{
String oneline;
//读取指定的HTML文件模板
while ((oneline = sr.ReadLine()) != null)
{
strhtml.Append(oneline);
}
sr.Close();
}
//这几个是用来替换的。
string FilePath = "";
strhtml = strhtml.Replace("$Title", title);
strhtml = strhtml.Replace("$NewsCaId", caid);
strhtml = strhtml.Replace("$NewsCaName", caname);
strhtml = strhtml.Replace("$Time", time);
strhtml = strhtml.Replace("$UserName", username);//这里需要循环输出
strhtml = strhtml.Replace("$Content", content);//这里需要循环输出
FilePath = Server.MapPath("~/") + "ITNews" + "//" + fileyyyymmdd + "//" + filename;
strhtml = strhtml.Replace("$SourceURL", sourceurl);
//创建文件信息对象--------------------------------------------
FileInfo finfo = new FileInfo(FilePath);
//以打开或者写入的形式创建文件流
using (FileStream fs = finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
//把新的内容写到创建的HTML页面中
sw.WriteLine(strhtml);
sw.Flush();
sw.Close();
}
}
catch (Exception ex)
{
//输出异常信息
Response.Write(ex.ToString());
}
#endregion
}
当用此代码来生成新闻页时没有问题
但我想用来生成循环数据,例如留言本,论坛的贴子时,我应如何实现?
相关推荐
struts2+freemarker 生成静态页面
**安全性**:虽然静态页面可以提高性能,但也要注意安全问题。比如,敏感信息不应被静态化,防止被非法获取;此外,定期清理过期的静态页面,防止旧版本的信息泄露。7.
从静态HTML到Next.js:构建可扩展SEO站点的架构实践
本文详述如何将传统静态HTML站点重构为基于Next.js的可扩展SEO友好型静态站点。核心包括:采用next export实现纯静态文件生成,结合配置驱动的动态路由批量生成城市/集成/用例页面;集中化元数据管理与自动生成sitemap.xml;CSS Modules组件化开发;适配GitHub Pages的构建部署流程;以及迁移过程中的404处理、样式失效、图片优化等实战问题解决方案。
运用 Freemarker 模板引擎为文章生成静态文件,将文件存放在分布式文件系统 MinIO 中,以及 Non-XML response from server问题的解决
前端传数据给服务端,服务端将数据渲染到Freemarker文件生成静态HTML,保存到MinIO并将地址存数据库。过程中遇到Non - XML response from server问题,新旧版本MinIO的yml配置不同。还探讨了更新慢时用户访问数据的问题及解决策略。
asp静态页生成程序,在线html静态页批量生成程序,网站转html程序代码
综上,这个ASP静态页生成程序是一个方便的工具,可以帮助ASP网站管理员快速生成静态HTML页面,提升网站性能和用户体验。但使用前应确保了解其工作原理和适用场景,以充分利用其优势并避免潜在问题。
PHP生成HTML静态页面实例代码
通过浏览器访问这个脚本,并带上适当的GET参数,脚本就会按照指定的参数生成静态页面。9. 代码优化与性能问题:代码中提到了生成速度一般,并建议生成数量不超过800条数据。


