ASPX頁生成靜態HTML頁

2021-06-27 03:27:24 字數 2675 閱讀 8721

商品detail資訊頁面都是html頁面,減少訪問資料庫的次數,提高效能

方案1: 

///    

///    傳入url返回網頁的html** 

///     

///    url  

///     

public    static      string    geturltohtml(string    url) 

//    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) 

return    ""; 

} 你可以用這個函式獲取網頁的客戶端的html**,然後儲存到.html檔案裡就可以了。 

方案2: 

生成單個的靜態頁面不是難點,難的是各個靜態頁面間的關聯和鏈結如何保持完整; 

特別是在頁面頻繁更新、修改、或刪除的情況下; 

像阿里巴巴的頁面也全部是html的,估計用的是位址對映的功能 

可以看看這個頁面,分析一下他的「競價倒計時」功能 

asp.net生成靜態html頁 

在asp中實現的生成靜態頁用到的filesystemobject物件! 

在.net中涉及此類操作的是system.io   

以下是程式**    注:此**非原創!參考別人** 

code:       

//生成html頁 

public    static    bool    writefile(string    strtext,string    strcontent,string    strauthor)   

catch(exception    exp) 

string    htmlfilename=datetime.now.tostring("yyyymmddhhmmss")+".html"; 

//    替換內容 

//    這時,模板檔案已經讀入到名稱為str的變數中了 

str    =str.replace("showarticle",strtext);    //模板頁中的showarticle 

str    =    str.replace("biaoti",strtext); 

str    =    str.replace("content",strcontent); 

str    =    str.replace("author",strauthor); 

//    寫檔案 

try 

catch(exception    ex) 

finally 

return    true; 

此函式放在conn.cs基類中了 

在新增新聞的**中引用    注:工程名為hover 

if(hover.conn.writefilethis.title.text.tostring),this.content.text.tostring),this.author.text.tostring))) 

else 

模板頁text.html** 

code:       

$htmlformat[3]

2.asp.net**:   

//---------------------讀html模板頁面到stringbuilder物件裡----   

string    format=new    string[4];//定義和htmlyem標記數目一致的陣列   

stringbuilder    htmltext=new    stringbuilder();   

try   

sr.close();   

}   

}   

catch   

//---------------------給標記陣列賦值------------   

format[0]="background="bg.jpg"";//背景   

format[1]=    "#990099";//字型顏色   

format[2]="150px";//字型大小   

format[3]=    "生成的模板html頁面";//文字說明   

//----------替換htm裡的標記為你想加的內容   

for(int    i=0;i<4;i++)   

//----------生成htm檔案------------------――   

try   

}   

catch   

小結   

用此方法可以方便的生成html檔案。程式使用了是迴圈替換,因此對需替換大量元素的模板速度非常快

aspx 生成HTML 靜態頁

cs 頁 using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui...

ASPX頁生成靜態HTML頁 五種方案

方案1 傳入url返回網頁的html url public static string geturltohtml string url get the response stream.system.io.stream respstream wresp.getresponsestream dim re...

aspx生成靜態htm頁

新建兩個類 1.freezablepage 它繼承自 system.web.ui.page。這個類用於重寫render方法,獲取頁面的htm輸出。2.myhtmlfilecreator 利用freezablepage輸出的htmltextwriter型物件,寫入新生成的htm靜態檔案。base.re...