当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET 生成静态页面 实现思路

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

老凤祥黄金价格查询,医生累倒躺地休息,胡木荣

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代码进行文件进行保存 平把路径存如数据库方便调用

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网