国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

使用ASP.NET模板生成HTML靜態(tài)頁(yè)面的五種方案

2024-07-10 12:41:42
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
ASP.NET模版生成HTML靜態(tài)頁(yè)面方案1:
代碼如下:
/// < summary>
/// 傳入U(xiǎn)RL返回網(wǎng)頁(yè)的html代碼
/// < /summary>
/// < param name="Url">URL< /param>
/// < returns>< /returns>
public static string getUrltoHtml(string Url)
{
errorMsg = "";
try
{
System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
// Get the response instance.
System.Net.WebResponse wResp =wReq.GetResponse();
// Read an HTTP-specific property
//if (wResp.GetType() ==HttpWebResponse)
//{
//DateTime updated =((System.Net.HttpWebResponse)wResp).LastModified;
//}
// Get the response stream.
System.IO.Stream respStream = wResp.GetResponseStream();
// Dim reader As StreamReader = New StreamReader(respStream)
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 "";
}

你可以用這個(gè)函數(shù)獲取網(wǎng)頁(yè)的客戶端的html代碼,然后保存到.html文件里就可以了。
ASP.NET模版生成HTML靜態(tài)頁(yè)面方案2:
生成單個(gè)的靜態(tài)頁(yè)面不是難點(diǎn),難的是各個(gè)靜態(tài)頁(yè)面間的關(guān)聯(lián)和鏈接如何保持完整;
特別是在頁(yè)面頻繁更新、修改、或刪除的情況下;
像阿里巴巴的頁(yè)面也全部是html的,估計(jì)用的是地址映射的功能
可以看看這個(gè)頁(yè)面,分析一下他的“競(jìng)價(jià)倒計(jì)時(shí)”功能
http://info.china.alibaba.com/news/subject/v1-s5011580.html?head=top4&Bidding=home5
ASP.Net生成靜態(tài)HTML頁(yè)
在Asp中實(shí)現(xiàn)的生成靜態(tài)頁(yè)用到的FileSystemObject對(duì)象!
在.Net中涉及此類(lèi)操作的是System.IO
以下是程序代碼 注:此代碼非原創(chuàng)!參考別人代碼
代碼如下:
//生成HTML頁(yè)
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/text.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();
}

string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
// 替換內(nèi)容
// 這時(shí),模板文件已經(jīng)讀入到名稱為str的變量中了
str =str.Replace("ShowArticle",strText); //模板頁(yè)中的ShowArticle
str = str.Replace("biaoti",strText);
str = str.Replace("content",strContent);
str = str.Replace("author",strAuthor);
// 寫(xiě)文件
try
{
sw = new StreamWriter(path + htmlfilename , false, code);
sw.Write(str);
sw.Flush();
}
catch(Exception ex)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 三明市| 长汀县| 合山市| 自贡市| 博罗县| 红安县| 南丰县| 响水县| 石首市| 涿州市| 麻阳| 吴川市| 东宁县| 平塘县| 北宁市| 区。| 安庆市| 丰台区| 淮阳县| 平远县| 江口县| 阜新| 乐亭县| 齐齐哈尔市| 正阳县| 鄄城县| 卢氏县| 太和县| 嘉祥县| 山西省| 武安市| 德昌县| 武陟县| 昆山市| 合肥市| 兴海县| 沅陵县| 丰都县| 通化市| 札达县| 新和县|