.aspx转换html文件!静态页面! 想的方法:1:最后一步 protected void Page_PreRender(object sender, EventArgs e)转化成html流2:听说有什么模板转化 不清楚 大家讲讲还有什么方法 不知道怎么实现的 讲讲原理 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一种方法省事!使用模版的话就是先创建一个空的html页:<html><head></head><body><!--body start--><!--body end--></body></html>然后读取该模版文件向注释中插入内容另存为注:之所以“插入”不是“替换”是为了以后方便修改 学习下 有没代码啊 发到我邮箱:[email protected] 谢谢! public static bool WriteFile(string strText,string saveUrl){ string text1 = Path.GetDirectoryName(HttpContext.Current.Server.MapPath(saveUrl)) + @"\"; Encoding encoding1 = Encoding.GetEncoding("utf-8"); string text2 = HttpContext.Current.Server.MapPath("/HTMLNews/mb.htm"); StreamReader reader1 = null; StreamWriter writer1 = null; string text3 = ""; try { reader1 = new StreamReader(text2, encoding1); text3 = reader1.ReadToEnd(); } catch (Exception exception1) { HttpContext.Current.Response.Write(exception1.Message); HttpContext.Current.Response.End(); reader1.Close(); } string text4 = "index.shtml"; text3 = text3.Replace("AllNewsContent", strText); text3 = text3.Replace("<title></title>", "<title>ASPX TO HTML</title>"); try { writer1 = new StreamWriter(text1 + text4, false, encoding1); writer1.Write(text3); writer1.Flush(); } catch (Exception exception2) { HttpContext.Current.Response.Write(exception2.Message); HttpContext.Current.Response.End(); } finally { writer1.Close(); } return true;} 用系统时间作为后缀名的html文怎么打出来 #region 写HTML public static void WriteHTML(StringBuilder htmlText) { //HTML字符串 //StringBuilder htmlText = new StringBuilder(""); try { using (StreamWriter sw = new StreamWriter(HTML_STATIC_PATH + StringUtil.GetStrDate() + ".html", false, System.Text.Encoding.GetEncoding("GB2312"))) { sw.WriteLine(htmlText); sw.Flush(); sw.Close(); } } catch (Exception ex) { //Response.Write("这个页面不能写成静态页面"); throw ex; } } #endregion url rewriter重写转换静态页或模板转化参考参考 我在下载专区发了个ASP.NET生成静态页的列子的,有代码很详细,你可以去下载了看. 真正的html静态页是通过转化才得来的... url rewriter这个很常用也很方便的我这有相关资料需要给我邮件:催[email protected] 模版替换··url rewriter http://www.svnhost.cn/Article/?k=%E9%9D%99%E6%80%81%E9%A1%B5%E9%9D%A2 用thickbox弹出一个层 ,该层上有Button 怎样触发它的后台OnClick 事件? 高分请教!! 这一行怎么变成Jquery 请问这句正确应该如何写 想找个适合心理学方面的网页模版~~~~~~ 如何设置一个DATAGRID的每条记录行的高度?属性生成器里只有列的设置(包括列的字体大小)? 急!!! 文件上传问题 ====怎样用table web 服务器控件画一张特殊的表格==== 孟子一章网站的地址是什么? asp.net采集网页数据需要多线程吗 后台设置参数应该使用什么文件? Linux平台的ASP.NET WEB服务器 Jexus V3.2版正式发布
使用模版的话就是先创建一个空的html页:
<html>
<head>
</head>
<body>
<!--body start--><!--body end-->
</body>
</html>
然后读取该模版文件向注释中插入内容另存为
注:之所以“插入”不是“替换”是为了以后方便修改
{
string text1 = Path.GetDirectoryName(HttpContext.Current.Server.MapPath(saveUrl)) + @"\";
Encoding encoding1 = Encoding.GetEncoding("utf-8");
string text2 = HttpContext.Current.Server.MapPath("/HTMLNews/mb.htm");
StreamReader reader1 = null;
StreamWriter writer1 = null;
string text3 = "";
try
{
reader1 = new StreamReader(text2, encoding1);
text3 = reader1.ReadToEnd();
}
catch (Exception exception1)
{
HttpContext.Current.Response.Write(exception1.Message);
HttpContext.Current.Response.End();
reader1.Close();
}
string text4 = "index.shtml";
text3 = text3.Replace("AllNewsContent", strText);
text3 = text3.Replace("<title></title>", "<title>ASPX TO HTML</title>");
try
{
writer1 = new StreamWriter(text1 + text4, false, encoding1);
writer1.Write(text3);
writer1.Flush();
}
catch (Exception exception2)
{
HttpContext.Current.Response.Write(exception2.Message);
HttpContext.Current.Response.End();
}
finally
{
writer1.Close();
}
return true;
}
怎么打出来
public static void WriteHTML(StringBuilder htmlText)
{
//HTML字符串
//StringBuilder htmlText = new StringBuilder(""); try
{
using (StreamWriter sw = new StreamWriter(HTML_STATIC_PATH + StringUtil.GetStrDate() + ".html", false, System.Text.Encoding.GetEncoding("GB2312")))
{
sw.WriteLine(htmlText);
sw.Flush();
sw.Close();
}
}
catch (Exception ex)
{
//Response.Write("这个页面不能写成静态页面");
throw ex;
} }
#endregion
参考
参考
这个很常用也很方便的我这有相关资料
需要给我邮件:催[email protected]