重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

ASP.NET中怎么使用模板引擎技术

本篇文章为大家展示了ASP.NET中怎么使用模板引擎技术,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

十载的六枝网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整六枝建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“六枝网站设计”,“六枝网站推广”以来,每个客户项目都认真落实执行。

Default.aspx这个页面只有几个textbox控件和两个按妞控件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" ValidateRequest="false" Inherits="ToHtml._Default" %>        Asp.net生成静态页            
         标题:         内容:                                             Url地址:                           
       

要准备的模板页代码,htm文件页面比较简单,如果有兴趣的朋友可以做成更复杂的模板页嘿嘿

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">        $title$ 生成静态页title>     <style type="text/css"> <!--  .STYLE1 {   font-size: 16px;   font-weight: bold;  }  -->     </style> </head> <body> <br /> <br /> <table width="100%" border="0" bgcolor="#339900">   <tr>     <td height="34" align="center" bgcolor="#FFFFFF"><span class="STYLE1">$title$ </span></td>   </tr>   <tr>     <td height="42" bgcolor="#FFFFFF"><br />       <br />     内容:$content$ </td>   </tr> </table>  </body> </html></pre><p>后台生成静态页面的代码Default.aspx.cs主要用到了文件操做</p><pre>sing System;  using System.Data;  using System.Configuration;  using System.Web;  using System.Web.Security;  using System.Web.UI;  using System.Web.UI.WebControls;  using System.Web.UI.WebControls.WebParts;  using System.Web.UI.HtmlControls;  using System.Net;  using System.Text;  using System.IO;   namespace ToHtml  {      //51aspx.com生成静态页演示文件,转载请保留该信息      public partial class _Default : System.Web.UI.Page      {          protected void Page_Load(object sender, EventArgs e)          {                       }           //根据模板生成,保持在html文件夹中(部分源码搜集于网络)          protected void Button1_Click(object sender, EventArgs e)          {              //源码是替换掉模板中的特征字符               string mbPath =Server.MapPath("template.htm");              Encoding code = Encoding.GetEncoding("gb2312");              StreamReader sr = null;              StreamWriter sw = null;              string str = null;               //读取              try             {                  sr = new StreamReader(mbPath, code);                  str = sr.ReadToEnd();               }              catch (Exception ex)              {                  throw ex;              }              finally             {                  sr.Close();              }               //根据时间自动重命名,扩展名也可以自行修改              string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";              str = str.Replace("$title$", txtTitle.Text);//替换Title              str = str.Replace("$content$", txtContent.Text);//替换content               //生成静态文件              try             {                  sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);                  sw.Write(str);                  sw.Flush();               }              catch (Exception ex)              {                  throw ex;              }              finally             {                  sw.Close();                  Response.Write("恭喜<a href=htm/"+fileName+" target=_blank>"+fileName+"</a>已经生成,保存在htm文件夹下!");              }            }            //根据Url地址生成静态页保持          protected void Button2_Click(object sender, EventArgs e)          {              Encoding code = Encoding.GetEncoding("utf-8");              StreamReader sr = null;              StreamWriter sw = null;              string str = null;               //读取远程路径              WebRequest temp = WebRequest.Create(txtUrl.Text.Trim());              WebResponse myTemp = temp.GetResponse();              sr = new StreamReader(myTemp.GetResponseStream(), code);              //读取              try             {                  sr = new StreamReader(myTemp.GetResponseStream(), code);                  str = sr.ReadToEnd();               }              catch (Exception ex)              {                  throw ex;              }              finally             {                  sr.Close();              }              string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";               //写入              try             {                  sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);                  sw.Write(str);                  sw.Flush();               }              catch (Exception ex)              {                  throw ex;              }              finally             {                  sw.Close();                  Response.Write("恭喜<a href=htm/" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在htm文件夹下!");              }           }      }  }</pre><p>上述内容就是ASP.NET中怎么使用模板引擎技术,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。</p>            
            
                        <br>
            分享题目:ASP.NET中怎么使用模板引擎技术            <br>
            当前URL:<a href="http://cqcxhl.com/article/pgcios.html">http://cqcxhl.com/article/pgcios.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/ddjshjd.html">go语言基础教程43讲 go语言基础知识</a>
                </li><li>
                    <a href="/article/ddjshje.html">智能聊天电影her the champ电影</a>
                </li><li>
                    <a href="/article/ddjshep.html">刚买的服务器如何退腾讯云 腾讯云买的服务器怎么退款</a>
                </li><li>
                    <a href="/article/ddjshjg.html">defer和go语言 go defer原理</a>
                </li><li>
                    <a href="/article/ddjshjc.html">云安全扫描服务器 云服务安全编码测试</a>
                </li>        </ul>
    </div>
</div>
<div class="footer">
    <div class="footer_content">
        <div class="footer_content_top clear">
            <div class="content_top_share fl">
                <div><img src="/Public/Home/img/logo.png"></div>
                <div class="top_share_content">
                    <dd>分享至:</dd>
                    <dt class="bdsharebuttonbox clear" id="share">
                        <a href="#" class="bds_tsina iconfont fl" data-cmd="tsina" title="分享到新浪微博"></a>
                        <a href="#" class="bds_sqq iconfont fl" data-cmd="sqq" title="分享到QQ好友"></a>
                        <a href="#" class="bds_weixin iconfont fl" data-cmd="weixin" title="分享到微信"></a>
                        <a href="#" class="bds_weixin iconfont fl" data-cmd="tieba" title="分享到贴吧"></a>
                    </dt>
                    <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
                </div>
            </div>
            <div class="content_top_left fl clear">
                <div class="top_left_list fl">
                    <dd><a href="/about/">关于我们</a></dd>
                    <dt>
                        <a href="/about/#gsjj">公司简介</a>
                        <a href="/about/#fzlc">发展历程</a>
                    </dt>
                </div>
                <div class="top_left_list fl">
                    <dd><a href="/service/">服务项目</a></dd>
                    <dt>
                        <a href="/service/">高端网站建设</a>
                        <a href="/miniprogram/">小程序开发</a>
                        <a href="/service/app.html">APP开发</a>
                        <a href="/service/yingxiao.html">网络营销</a>
                    </dt>
                </div>
                <div class="top_left_list fl">
                    <dd><a href="/jianzhan/">建站知识</a></dd>
                    <dt>
                        <a href="/jianzhan/2.html">网站建设</a>
                        <a href="/jianzhan/3.html">网站设计</a>
                        <a href="/jianzhan/4.html">网站制作</a>
                        <a href="/jianzhan/5.html">小程序</a>
                    </dt>
                </div>
                <div class="top_left_list fl">
                    <dd><a href="/contact/">联系我们</a></dd>
                    <dt>
                        <a href="/contact/#lxwm">公司地址</a>
                        <a href="/contact/#rczp">人才招聘</a>
                    </dt>
                </div>
            </div>
            <div class="content_top_right addressR fr">
                <div class="top_right_title addressf_title">
                    <a href="javascript:;" class="on">成都</a>
                    <a href="javascript:;">重庆</a>
                </div>
                <div class="top_right_content addressf">
                    <div class="right_content_li on">
                        <div class="right_content_list clear">
                            <dd class="fl iconfont"></dd>
                            <dt class="fl">电话:028-86922220</dt>
                        </div>
                        <div class="right_content_list clear">
                            <dd class="fl iconfont"></dd>
                            <dt class="fl">地址:成都市太升南路288号锦天国际A幢1002号</dt>
                        </div>
                    </div>
                    <div class="right_content_li">
                        <div class="right_content_list clear">
                            <dd class="fl iconfont"></dd>
                            <dt class="fl">电话:028-86922220</dt>
                        </div>
                        <div class="right_content_list clear">
                            <dd class="fl iconfont"></dd>
                            <dt class="fl">地址:重庆市南岸区弹子石腾龙大道58号2栋21-6</dt>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="footer_content_copyright clear">版权所有:成都创新互联科技有限公司重庆分公司
        <a href="http://beian.miit.gov.cn/" rel="nofollow" target="_blank">渝ICP备2021005571号-4</a>
    </div>
</div>

<!--浮窗-->
<div class="FloatingWindow clear">
    <a href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="FloatingWindow_list fr">
        <div class="FloatingWindow_list_title">
            <dd class="iconfont"></dd>
            <dt><span>在线</span>咨询</dt>
        </div>
    </a>
    <a href="javascript:;" class="FloatingWindow_list fr">
        <div class="FloatingWindow_list_title">
            <dd class="iconfont"></dd>
            <dt>服务热线</dt>
        </div>
        <div class="FloatingWindow_list_down fadeInRight animated">服务热线:028-86922220</div>
    </a>
    <a href="javascript:;" class="FloatingWindow_list fr STop">
        <div class="FloatingWindow_list_title">
            <dd class="iconfont"></dd>
            <dt>TOP</dt>
        </div>
    </a>
</div>
<script src="/Public/Home/js/jquery-1.8.3.min.js"></script>
<script src="/Public/Home/js/comm.js"></script>
<script src="/Public/Home/js/wow.js"></script>
<script src="/Public/Home/js/common.js"></script>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
</script>