ASP.NET 生成静态页面 实现思路
更新时间:2009年06月25日 13:32:44 作者:
网上的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代码进行文件进行保存 平把路径存如数据库方便调用
然后再该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代码进行文件进行保存 平把路径存如数据库方便调用
您可能感兴趣的文章:
- ASP.NET MVC3关于生成纯静态后如何不再走路由直接访问静态页面
- 使用ASP.NET模板生成HTML静态页面的五种方案
- ASP.NET动态生成静态页面的实例代码
- Asp.NET 生成静态页面并分页的代码
- Asp.Net生成静态页面的实现方法
- ASP.NET MVC生成静态页面的方法
- asp.net生成Excel并导出下载五种实现方法
- asp.net(C#) 生成随机验证码的代码
- ASP.net(c#)生成条形码 code39条码生成方法
- asp.net C#生成和解析二维码的实例代码
- Asp.net生成Excel文件并下载(更新:解决使用迅雷下载页面而不是文件的问题)
- ASP.NET编程简单实现生成静态页面的方法【附demo源码下载】
相关文章
使用Fiddler调试visual studion多个虚拟站点的问题分析
本篇文章小编为大家介绍,使用Fiddler调试visual studion多个虚拟站点的问题分析。需要的朋友参考下2013-04-04解决asp.net mvc UpdateModel更新对象后出现null问题的方法
这篇文章主要介绍了解决asp.net mvc UpdateModel 更新对象后出现null问题的方法,需要的朋友可以参考下2015-11-11深入解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析
许可证编译器 (Lc.exe) 的作用是读取包含授权信息的文本文件,并产生一个可作为资源嵌入到公用语言运行库可执行文件中的 .licenses 文件2013-07-07asp.net中使用cookie与md5加密实现记住密码功能的实现代码
虽然.net内置了登陆控件,有记住密码的功能,但还是想自己实践一下,以下代码主要应用了COOKIE,包括安全加密的过程等2013-02-02
最新评论