ASP.NET页面静态化***步:首页选择HTML原型网页
然后再该HTML网页添加一些自认为特别的标记,已便到时候静态化的时候系统能更精确的进行操作!
ASP.NET页面静态化第二步:获取HTML网页代码
我选择的是通过FileUpload控件进行获取静态度页面模型,进行保存!
if (FileUpload1.PostedFile.FileName == "")
{
Response.Write("");
return;
}
if ((FileUpload1.FileName.LastIndexOf(".") != "htm") ||
(FileUpload1.FileName.LastIndexOf(".") != "html"))
{
Response.Write("");
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方法代码
///
/// 格式 化 HTML
///
///
///
private string FormatStr(string str)
{
string strContent = str.Replace("<", "<");
strContent = strContent.Replace(">", ">");
//strContent = strContent.Replace(chr(13),"
");
strContent = strContent.Replace(" ", "
");
strContent = strContent.Replace(" ", " ");
strContent = strContent.Replace("[isOK]", "
strContent = strContent.Replace("[red]", "");
strContent = strContent.Replace("[big]", "");
strContent = strContent.Replace("[/isOK]", ">");
strContent = strContent.Replace("[/b]", "");
strContent = strContent.Replace("[/red]", "");
strContent = strContent.Replace("[/big]", "");
return strContent;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
ASP.NET页面静态化第三步:提取先前保存过的HTML页面模型
然后通过 string.Replace(char oldstring,char newstring );
对模型页面中预先 设置好的特别标记进行替换成我们需要动态更改的!
ASP.NET页面静态化第四步:对动态更新后的HTML代码进行文件进行保存 平把路径存如数据库方便调用!
【编辑推荐】