茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    ASP.NET靜態(tài)頁生成方法
    來源:易賢網(wǎng) 閱讀:927 次 日期:2014-12-01 11:38:37
    溫馨提示:易賢網(wǎng)小編為您整理了“ASP.NET靜態(tài)頁生成方法”,方便廣大網(wǎng)友查閱!

    本文實例講述了ASP.NET靜態(tài)頁生成方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

    一、問題:

    由于業(yè)務需要,得把頁面按照模板頁生成靜態(tài)頁面,所以自己就琢磨了下,寫些思路,以備日后需要的時候用。

    二、解決方法:

    靜態(tài)頁生成用到最多的就是匹配跟替換了,首先得讀取模板頁的html內(nèi)容,然后進行你自己定義的標簽匹配,比如說我要把我定義的標題標簽換成讀取數(shù)據(jù)庫的標題內(nèi)容,那么可以直接讀取數(shù)據(jù)庫的標題,然后直接進行替換,然后生成html文件就OK了。

    具體代碼如下:

    復制代碼 代碼如下:/// <summary>

    /// 解析模板的html中匹配的標簽,進行替換(暫時只能用于沒有分頁的頁面)

    /// </summary>

    /// <param name="html">HTML</param>

    /// <returns>返回替換后的HTML</returns>

    public static string ReturnHtml(string html)

    {

    string newhtml = html;

    newhtml = newhtml.Replace("<#Title#>", "這個是標題替換");//替換標題

    //newhtml = newhtml.Replace("<#Content#>", "這個是內(nèi)容替換");//替換標題

    newhtml = CreateList(newhtml);

    return newhtml;

    }

    /// <summary>

    /// 讀取HTML文件

    /// </summary>

    /// <param name="temp">html文件的相對路徑</param>

    /// <returns>返回html</returns>

    public static string ReadHtmlFile(string temp)

    {

    StreamReader sr = null;

    string str = "";

    try

    {

    sr = new StreamReader(HttpContext.Current.Server.MapPath(temp), code);

    str = sr.ReadToEnd(); // 讀取文件

    }

    catch (Exception exp)

    {

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

    HttpContext.Current.Response.End();

    }

    finally

    {

    sr.Dispose();

    sr.Close();

    }

    return str;

    }

    /// <summary>

    /// 生成html文件

    /// </summary>

    /// <param name="filmname">文件名(帶相對路徑路徑,如:../a.html)</param>

    /// <param name="html">html內(nèi)容(整個)</param>

    public static void writeHtml(string filmname, string html)

    {

    System.Text.Encoding code = System.Text.Encoding.GetEncoding("utf-8");

    string htmlfilename = HttpContext.Current.Server.MapPath(filmname);

    string str = html;

    StreamWriter sw = null;

    // 寫文件

    try

    {

    sw = new StreamWriter(htmlfilename, false, code);

    sw.Write(str);

    sw.Flush();

    }

    catch (Exception ex)

    {

    HttpContext.Current.Response.Write(ex.Message);

    HttpContext.Current.Response.End();

    }

    finally

    {

    sw.Close();

    }

    }

    從代碼可以看得出來,生成靜態(tài)頁面其實就是這么一個過程:讀取模板頁的源碼->匹配替換自定義的標簽為實際內(nèi)容->最后再生成新的html文件,思路就這么走,以前沒有動手過,覺得太復雜了,如今主動寫的時候,發(fā)現(xiàn)也不算很復雜。

    最后,如果說有些生成分頁列表的,也就是把列表頁面進行循環(huán)生成,有多少頁就生成多少個靜態(tài)頁文件,如果有不懂的可以回復問,我懂的我盡量為大家解答,當然,不懂的我也無能為力了,畢竟我也是剛接觸這功能,現(xiàn)在暫時弄得一個最簡陋的樣子,附圖上來給大家笑話笑話:

    名單

    更多信息請查看IT技術專欄

    更多信息請查看網(wǎng)絡編程
    易賢網(wǎng)手機網(wǎng)站地址:ASP.NET靜態(tài)頁生成方法

    2026上岸·考公考編培訓報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)