如何快速生产HTML网页及实现网页静态化

html-css08

如何快速生产HTML网页及实现网页静态化,第1张

动态页面如aspx,php等以html,shtml等形式表示

可用模板或urlrewriter静态化

public static bool WriteFile(string strText,string strContent,string strAuthor)

{

string path = HttpContext.Current.Server.MapPath("/news/")

Encoding code = Encoding.GetEncoding("gb2312")

string temp = HttpContext.Current.Server.MapPath("/news/template.html")

StreamReader sr=null

StreamWriter sw=null

string str=""

try

{

sr = new StreamReader(temp, code)

str = sr.ReadToEnd()

}

catch(Exception exp)

{

HttpContext.Current.Response.Write(exp.Message)

HttpContext.Current.Response.End()

sr.Close()

}

public static string getUrltoHtml(string Url)

{

errorMsg = ""

try

{

System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url)

System.Net.WebResponse wResp =wReq.GetResponse()

System.IO.Stream respStream = wResp.GetResponseStream()

System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"))

return reader.ReadToEnd()

}

catch(System.Exception ex)

{

errorMsg = ex.Message

}

return ""

}

静态网页是服务器上面真实存在的页面,它不需要编译,用户就可以直接访问静态网页。

在网站优化工作中,静态化页面对SEO非常友好:

1、网页打开速度快,因为是直接读取文件;

2、有利于搜索引擎的抓取收录;

3、静态网页相对比较稳定,对服务器友好;

4、一些面对数据库的攻击比如SQL注入攻击,在面对静态网页的时候常常难以从地址入手。