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

ASP.NET
用ASP.NET加密Cookie数据
用ASP.NET开发Web服务的五则技巧
ASP.NET数据库缓存依赖
ASP.Net开发者常见Datagrid错误
asp.net 2.0多语言网站解决方案
在ASP.NET中值得注意的两个地方
用.net静态变量取代Application 速度更快
ASP.NET图象处理详解(1)
ASP.NET图象处理详解(2)
使用JScript.NET创建asp.net页面
ASP.NET中水晶报表的使用
数据库连接字在Web.config里的用法
浅谈在ASP.NET中数据有效性校验的方法
ASPX页Web服务调用性能优化
从 PHP 迁移到 ASP.NET
ASP.NET中编程杀死进程
ASP.NET保持用户状态的九种选择(上)
ASP.NET保持用户状态的九种选择(下)
使用更精简的代码保证ASP.NET应用程序的安全
为ASP.NET应用缓存Oracle数据

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 139 ::
收藏到网摘: 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代码进行文件进行保存 平把路径存如数据库方便调用