c#寫的一個html模板方案,不知道大家在asp.net上面使用的是不是也是這個原理

來源:互聯網
上載者:User

標籤:

因為小弟寫個方法還是很容易的,但是對於前端相關的東西卻不是很懂,在我自己做銅梁視窗這個小站的時候,涉及到每個頻道一個模板,每個頻道的相關頁面也是一個模板,小弟沒有吧html寫在aspx上面,然後在匹配模板的時候發現很多有些模板是可以公用的,例如首頁的head部分,還有其他的頻道head部分,還有footer部分,所以寫了下面這麼一個東西來控制每個頁面的模板調用,不知道對不對哈。請各位大牛小牛賜教!

對了,在運營過程中,我伺服器每個月會產生1%的磁碟片段,不知道是否跟這個模板方案有關

 /// <summary>        /// dir 是template目錄下的分檔案夾,shop,m,以及其他        /// </summary>        /// <param name="dir"></param>        /// <param name="tpl"></param>        /// <returns></returns>        public static string GetPageContent(string dir, string tpl)        {            string key = dir + "_" + tpl + "_CONTENT";            string contentkey = dir + "_CONTENT_CONTENT";            string temp = "";            if (DataCache.GetCache(key) == null)            {                string filepath = "/Template/" + dir + (dir.Length > 0 ? "/" : "") + tpl + ".html";                temp = File.ReadAllText(HttpContext.Current.Server.MapPath(filepath), Encoding.UTF8);                DataCache.SetCache(key, temp);            }            else            {                temp = DataCache.GetCache(key).ToString();            }            string content = "";            if (DataCache.GetCache(contentkey) == null)            {                content = File.ReadAllText(HttpContext.Current.Server.MapPath("/Template/" + dir + "/Content.html"), Encoding.UTF8);                DataCache.SetCache(contentkey, content);            }            else            {                content = DataCache.GetCache(contentkey).ToString();            }            string html = content.Replace("<$inner$>", temp);            string headstr = (string)DataCache.GetCache("HEADCONTENT");            string footstr = (string)DataCache.GetCache("FOOTCONTENT");            if (headstr == null || footstr == null)            {                headstr = File.ReadAllText(HttpContext.Current.Server.MapPath("/Template/head.html"), Encoding.UTF8);                footstr = File.ReadAllText(HttpContext.Current.Server.MapPath("/Template/foot.html"), Encoding.UTF8);                DataCache.SetCache("HEADCONTENT", headstr);                DataCache.SetCache("FOOTCONTENT", footstr);            }                        html = html.Replace("<$footcontent$>", footstr);            html = html.Replace("<$headcontent$>", headstr);            if (!string.IsNullOrEmpty(dir))            {                CMS_SEO seo = GetCurrectSeo(dir);                html = html.Replace("<$seoname$>", seo.SiteName);                html = html.Replace("<$seourl$>", seo.SiteUrl);                html = html.Replace("<$seoaddress$>", seo.Address);                html = html.Replace("<$seocopyright$>", seo.Copyright);                html = html.Replace("<$seodescription$>", seo.Description);                html = html.Replace("<$seoemail$>", seo.Email);                html = html.Replace("<$seoicp$>", seo.ICP);                html = html.Replace("<$seokeywords$>", seo.Keywords);                html = html.Replace("<$seologo$>", seo.Logo);                html = html.Replace("<$seotel$>", seo.Tel);                html = html.Replace("<$seoweixin$>", seo.Weixin);                html = html.Replace("<$seoworktime$>", seo.WorkTime);                html = html.Replace("<$OnlineChart$>", seo.OnlineChart);            }            html = html.Replace("<$token$>", DateTime.Now.AddHours(1).Ticks + "");            //廣告位                        html = html.Replace("<$DetailBottom$>", GetAdScript("DetailBottom"));            html = html.Replace("<$RightContent$>", GetAdScript("RightContent"));            html = html.Replace("<$BottomAd$>", GetAdScript("BottomAd"));            //廣告位結束            html = new BLL_Adv().GetPlaceTag(html, dir);            return html;        }

  小弟程式不精,請各位關照關照,順便看看小弟的小站有何改進之處---》銅梁視窗

c#寫的一個html模板方案,不知道大家在asp.net上面使用的是不是也是這個原理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.