网站建设资讯

NEWS

网站建设资讯

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>
            文章来源:<a href="http://cdweb.net/article/pgcios.html">http://cdweb.net/article/pgcios.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dihooie.html">怎么创建mysql索引 mysql 怎么建索引</a>
                </li><li>
                    <a href="/article/dihoosc.html">jquery循环次数 jqueryfor循环</a>
                </li><li>
                    <a href="/article/dihooej.html">css标题样式优化 css设置标题字体</a>
                </li><li>
                    <a href="/article/dihoogc.html">怎么看MySQL装好了没 怎么看mysql有没有安装成功</a>
                </li><li>
                    <a href="/article/dihoojo.html">mysql怎么备份和还原 mysql的备份与恢复</a>
                </li>        </ul>
    </div>
</div>
</div>
<footer>
    <div class="footop">
        <div class="wrap">
            <div class="bottomrpw">
                <div class="erp arp">
                    <dl>
                        <dt>ADDRESS</dt>
                        <dd class="address"> <i class="icon"></i> <span class="word">成都市青羊区锦天国际1号楼1002室</span> </dd>
                    </dl>
                </div>
                <div class="erp arp">
                    <dl>
                        <dt>TEL</dt>
                        <dd class="phonum"> <i class="icon"></i> <span class="word en"> <a href="tel:18980820575">18980820575</a> </span> </dd>
                    </dl>
                </div>
                <div class="erp crp">
                    <dl>
                        <dt>OTHER</dt>
                        <dd> <a class="word get-quote">获得报价与方案</a> </dd>
                        <dd> <a href="#" target="_blank" rel='nofollow' class="word" title="付款方式">付款方式</a> </dd>
                    </dl>
                </div>
                <div class="erp code-rp">
                    <dl>
                        <dt>Wechat</dt>
                        <dd class="code-wrap"> <span class="code"> <img src="/Public/Home/images/qr-code.jpg" alt="快上网微信公众号" /> </span> </dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
    <div class="footerbot">
        <div class="friendlinks">
            <div class="wrap">
                <ul class="rpl">
                    <li><a href="http://www.cdxwcx.cn/seo/" title="成都网络营销公司" target="_blank">成都网络营销公司</a></li><li><a href="https://www.cdcxhl.com/tuoguan/" title="成都托管服务器" target="_blank">成都托管服务器</a></li><li><a href="http://www.hongyifilm.cn/" title="鸿艺文化传播" target="_blank">鸿艺文化传播</a></li><li><a href="http://www.kswjz.com/" title="微信小程序开发" target="_blank">微信小程序开发</a></li><li><a href="http://www.cdxwcx.cn/tuoguan/meishan.html" title="眉山电信机房托管" target="_blank">眉山电信机房托管</a></li><li><a href="https://www.cdcxhl.com/hangyead/" title="一元广告" target="_blank">一元广告</a></li><li><a href="https://www.cdcxhl.com/shoulu/" title="免费收录网站" target="_blank">免费收录网站</a></li><li><a href="https://www.cdxwcx.com/" title="成都网站推广" target="_blank">成都网站推广</a></li><li><a href="http://www.cdxwcx.cn/tuoguan/meishan.html" title="眉山托管服务器" target="_blank">眉山托管服务器</a></li><li><a href="http://www.cxjianzhan.com/seo/" title="快照排名" target="_blank">快照排名</a></li>                </ul>
            </div>
        </div>
        <div class="wrap">
            <div class="copyright"> <span class="en">©2007-2022</span> 成都快上网科技有限公司 <span class="en">ALL RIGHTS
                        RESERVED.</span> <a rel="nofollow" href="http://www.miitbeian.gov.cn" target="_blank">蜀ICP备19037934号</a> </div>
        </div>
    </div>
</footer>
<div class="fcwrap">
    <ul class="rpl clearfix">
        <li class="phone"> <a rel="nofollow" target="_blank" href="tel:18980820575"> <i class="icon"></i>
            <strong>18980820575</strong> </a> </li>
        <li class="qq"> <a rel="nofollow" target="_blank"
                           href="https://wpa.qq.com/msgrd?v=1&uin=244261566&site=qq&menu=yes"> <i class="icon"></i>
            <strong>244261566</strong> </a> </li>
        <li class="back-top"> <a href="javascript:void(0)" rel="nofollow" class="back-to-top"> <i class="icon"></i>
            <strong>回到顶部</strong> </a> </li>
    </ul>
</div>
<!--nav-->
<div class="n-Wrap">
    <div class="navBar visble show">
        <div class="barlogo">
            <a href="/" rel="nofollow">
                <img src="/Public/Home/images/logo1.png" alt="成都做网站" />
                <img src="/Public/Home/images/logo2.png" alt="成都网站设计" />
            </a>
        </div>
        <div class="bmenu">
            <i class="bar-top"><span></span></i>
            <i class="bar-cen"><span></span></i>
            <i class="bar-bom"><span></span></i>
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
    </div>
    <section class="fixmenu">
        <div class="close-bar">
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
        <nav class="smph">
            <ul>
                <li class="index-hrefs on"><a href="http://www.cdweb.net/"><font>首页</font></a></li>
                <li><a href="/about/" rel="nofollow"><font>关于快上网</font></a></li>
                <li><a href="/service/" rel="nofollow"><font>服务范围</font></a></li>
                <li><a href="/case/" rel="nofollow"><font>案例展示</font></a></li>
                <li><a href="/solve/" rel="nofollow"><font>解决方案</font></a></li>
                <li><a href="/news/" rel="nofollow"><font>建站资讯</font></a></li>
                <li><a href="/contact/" rel="nofollow"><font>联系快上网</font></a></li>
            </ul>
            <div class="pwrap">
                <span class="label">服务热线</span>
                <strong class="phone"><a href="tel:18980820575">18980820575</a></strong>
            </div>
        </nav>
    </section>
</div>
<!--end nav-->
<script src="/Public/Home/js/hotcss.js"></script>
<script type="text/javascript" src="/Public/Home/js/su_new.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);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>