当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET 生成静态页面 实现思路

ASP.NET
十天学会ASP.net之第二天
十天学会ASP.net之第四天
十天学会ASP.net之第五天
十天学会ASP.net之第六天
十天学会ASP.net之第七天
十天学会ASP.net之第八天
十天学会ASP.net之第九天
十天学会ASP.net之第十天
在.net中Oracle日期类型的处理
ASP.Net的6大焦点问题
关于Web站点不同,共享Session的问题
判断浏览器是否接受Cookies
DataGrid的多行提交
C#中连接两个DataTable,相当于Sql的InnerJoin
ASP.Net常用功能整理--生成图片的缩略图
在程序中书写SQL语句
正则表达式的3种匹配模式
ASP.NET的高级调试技巧
基于C#的接口基础教程之七
ASP.NET对IIS中的虚拟目录进行操作

ASP.NET 生成静态页面 实现思路


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 62 ::
收藏到网摘: n/a

网上的cms系统好多都是支持生成静态的,大家在使用过程中,也肯定遇到了很多的问题,下面就是一些实现的原理,其实 asp,php,asp.net的原理都是差不多的。 1.首页选择HTML原型网页
然后再该HTML网页添加一些自认为特别的标记,已便到时候静态化的时候系统能更精确的进行操作!
2.获取HTML网页代码
我选择的是通过FileUpload控件进行获取静态度页面模型,进行保存!
复制代码 代码如下:

if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("<script>alert('请确定您是否选择了网页')</script>");
return;
}
if ((FileUpload1.FileName.LastIndexOf(".") != "htm") || (FileUpload1.FileName.LastIndexOf(".") != "html"))
{
Response.Write("<script>alert('请确定您是否选择了网页')</script>");
return;
}
System.Text.Encoding ec = System.Text.Encoding.GetEncoding("gb2312");//指定编码格式
System.IO.StreamReader sr = new System.IO.StreamReader(FileUpload1.PostedFile.FileName, ec);
string strHTML =Convert.ToString(sr.ReadToEnd());
strHTML=FormatStr(strHTML); //格式化HTML代码后,将此strHTML插入数据库 已便使用时候提取!
sr.Close();
//贴上格式化HTML方法代码
/// <summary>
/// 格式 化 HTML
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private string FormatStr(string str)
{
string strContent = str.Replace("<", "<");
strContent = strContent.Replace(">", ">");
//strContent = strContent.Replace(chr(13),"<br>");
strContent = strContent.Replace("\r", "<br>");
strContent = strContent.Replace(" ", " ");
strContent = strContent.Replace("[isOK]", "<img src=");
strContent = strContent.Replace("[b]", "<b>");
strContent = strContent.Replace("[red]", "<font color=CC0000>");
strContent = strContent.Replace("[big]", "<font size=7>");
strContent = strContent.Replace("[/isOK]", "></img>");
strContent = strContent.Replace("[/b]", "</b>");
strContent = strContent.Replace("[/red]", "</font>");
strContent = strContent.Replace("[/big]", "</font>");
return strContent;
}

3.提取先前保存过的HTML页面模型
然后通过 string.Replace(char oldstring,char newstring );
对模型页面中预先 设置好的特别标记进行替换成我们需要动态更改的!
4.对动态更新后的HTML代码进行文件进行保存 平把路径存如数据库方便调用