欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-09 10:34:29
1.首页选择html原型网页 然后再该html网页添加一些自认为特别的标记,已便到时候静态化的时候系统能更精确的进行操作! 2.获取html网页代码 我选择的是通过file...
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代码进行文件进行保存 平把路径存如数据库方便调用