用 aspx(C#) 发布的新闻,如何能按 年月日 的目录 生成静态 html 页呢? 100分 用 aspx(C#) 发布的新闻,如何能按 年月日 的目录 生成静态 html 页呢?求一个完美些的解决方案!多谢各位高人帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是一个ASPX页面动态转静态的问题,我所知的有两种方法.方法1:使用模板转换.方法2: 重写AttributeCollection.Render请参考一个地方:http://www.cnblogs.com/smh188/archive/2007/07/13/817735.html 完美??完美即是不存在。给你一个不能算是完美的文章。将Asp.net页面输出为HTML http://blog.csdn.net/octverve/archive/2007/09/04/1771107.aspx自己再灵活的改一下。应该是适合你说的 http://topic.csdn.net/t/20051127/12/4420997.html 首先要有个摸板html页,如下<html xmlns="http://www.w3.org/1999/xhtml" ><HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>$ShowArticle$</title> </HEAD> <body> 标题:$biaoti$ <br/> 内容开始<br/><br/> $content$<br/> <br/><br/>作者:$author$ <br/>结束 </body></HTML> 然后是CS代码,如下 protected void LoadStaticPage(string strText, string Biaoti, string strContent, string strAuthor) { string path = HttpContext.Current.Server.MapPath("FilePath/"); Encoding code = Encoding.GetEncoding("gb2312"); // 读取模板文件 string temp = HttpContext.Current.Server.MapPath("FilePath/Text.html"); StreamReader sr = null; StreamWriter sw = null; string str = ""; try { sr = new StreamReader(temp, code); str = sr.ReadToEnd(); // 读取文件 } catch (Exception exp) { HttpContext.Current.Response.Write(exp.Message); HttpContext.Current.Response.End(); sr.Close(); } //string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; string htmlfilename = "Text1.html"; // 替换内容 // 这时,模板文件已经读入到名称为str的变量中了 str = str.Replace("$ShowArticle$", strText); //模板页中的ShowArticle str = str.Replace("$biaoti$", Biaoti); str = str.Replace("$content$", strContent); str = str.Replace("$author$", strAuthor); // 写文件 try { sw = new StreamWriter(path + htmlfilename, false, code); sw.Write(str); sw.Flush(); } catch (Exception ex) { HttpContext.Current.Response.Write(ex.Message); HttpContext.Current.Response.End(); } finally { sw.Close(); } Response.Redirect("FilePath/Text1.html"); } LoadStaticPage里的参数,根据你的需要在HTML页中显示的传入。最后重新生成一个新的HTML页,我给出了根据年月日定义页面的代码段。你参考一下 先根据文章的日期获取年/月/日的目录名字。判断年月日目录是否存在。不存在创建他们。在日目录中生成html文件不知道lz想要的完美方案是什么? 求“大于50”的正则表达式 站点导航问题 GridView 列表消失的问题 response.write()下载问题. .net数据结构 线性表 存储数据 优化索引 实际例子 子目录中配置身份验证出错! 使用自定义控件时,跳出文件下载对话框的问题 请问如何在asp.net中使用javascript语句弹出一个对话框?(alert())谢谢,在线等! 在gridview里添加一个button (确认发货) 点击之后 显示 已发货 未能找到默认的成员资格提供程序。 关于查询字符串的问题?请高手指导!先谢谢 TreeView加checkbox多行更新问题
方法1:使用模板转换.
方法2: 重写AttributeCollection.Render
请参考一个地方:
http://www.cnblogs.com/smh188/archive/2007/07/13/817735.html
给你一个不能算是完美的文章。
将Asp.net页面输出为HTML
http://blog.csdn.net/octverve/archive/2007/09/04/1771107.aspx
自己再灵活的改一下。应该是适合你说的
<html xmlns="http://www.w3.org/1999/xhtml" >
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>$ShowArticle$</title>
</HEAD>
<body>
标题:$biaoti$
<br/>
内容开始<br/><br/>
$content$<br/>
<br/><br/>作者:$author$
<br/>结束
</body>
</HTML>
protected void LoadStaticPage(string strText, string Biaoti, string strContent, string strAuthor)
{
string path = HttpContext.Current.Server.MapPath("FilePath/");
Encoding code = Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("FilePath/Text.html");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
} //string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
string htmlfilename = "Text1.html";
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("$ShowArticle$", strText); //模板页中的ShowArticle
str = str.Replace("$biaoti$", Biaoti);
str = str.Replace("$content$", strContent);
str = str.Replace("$author$", strAuthor);
// 写文件
try
{
sw = new StreamWriter(path + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
{
sw.Close();
}
Response.Redirect("FilePath/Text1.html");
}
最后重新生成一个新的HTML页,我给出了根据年月日定义页面的代码段。
你参考一下