成都创新互联网站制作重庆分公司

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://cxhlcq.com/article/pgcios.html">http://cxhlcq.com/article/pgcios.html</a>
        </div>
    </div>
</div>
<div class="other container">
    <h3>其他资讯</h3>
    <ul>
        <li>
                <a href="/article/dsiogde.html">基站android,基站延迟是什么意思</a>
            </li><li>
                <a href="/article/dsiogds.html">windows系统手写的简单介绍</a>
            </li><li>
                <a href="/article/dsiogop.html">鸿蒙开发demo,鸿蒙开发的原班人马</a>
            </li><li>
                <a href="/article/dsioipe.html">包含macos重做系统的词条</a>
            </li><li>
                <a href="/article/dsiogog.html">macos系统操作技巧的简单介绍</a>
            </li>    </ul>
</div>
<div class="footer">
    <div class="foota container">
        <div class="foot_nav fl col-lg-8 col-md-8 col-sm-12 col-xs-12">
            <ul>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站制作</h3>
                    <a href="http://www.cxhljz.cn/" target="_blank">成都网站制作</a><a href="http://m.cdcxhl.com/" target="_blank">成都网站制作</a><a href="http://www.cqcxhl.com/" target="_blank">网站制作</a><a href="https://www.cdxwcx.com/" target="_blank">成都网站制作</a><a href="http://www.myzitong.com/" target="_blank">梓潼网站制作公司</a><a href="http://www.kswsj.com/" target="_blank">成都网站制作</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>企业服务</h3>
                    <a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文营销</a><a href="https://www.cdcxhl.com/service/guangdianxuke.html" target="_blank">广播电视节目制作许可证</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文推广</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">免费收录网站</a><a href="https://www.cdcxhl.com/link/" target="_blank">卖友情链接</a><a href="https://www.cdcxhl.com/service/gongsibiangeng.html" target="_blank">工商变更</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站建设</h3>
                    <a href="http://seo.cdkjz.cn/yingxiao/" target="_blank">营销型网站建设</a><a href="http://www.cxhlcq.com/mobile/" target="_blank">重庆移动网站建设</a><a href="http://www.cdkjz.cn/wangzhan/jituan/" target="_blank">成都集团网站建设</a><a href="https://www.cdxwcx.com/city/shuangliu/" target="_blank">双流网站建设</a><a href="http://www.cqwzjz.cn/" target="_blank">重庆网站建设</a><a href="https://www.cdxwcx.com/city/ziyang/" target="_blank">资阳网站建设</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>服务器托管</h3>
                    <a href="https://www.cdcxhl.com/tuoguan/zongshu/" target="_blank">成都棕树机房</a><a href="http://www.cqfuwuqi.com/" target="_blank">重庆服务器托管</a><a href="http://www.cdfuwuqi.com/tuoguan/duoxian/" target="_blank">多线服务器托管</a><a href="http://www.cdfuwuqi.com/jigui/" target="_blank">成都机柜租用</a><a href="https://www.cdxwcx.com/jifang/guanghua.html" target="_blank">光华服务器托管</a><a href="https://www.cdxwcx.com/jifang/yaan.html" target="_blank">雅安服务器托管</a>                </li>
            </ul>
        </div>
        <div class="footar fl col-lg-4 col-md-4 col-sm-12 col-xs-12">
            <p>全国免费咨询:</p>
            <b>400-028-6601</b>
            <p>业务咨询:028-86922220 / 13518219792</p>
            <p>节假值班:18980820575 / 13518219792</p>
            <p>联系地址:成都市太升南路288号锦天国际A幢1002号</p>
        </div>
    </div>
    <div class="footb">
        <div class="copy container">
            <div class="fl">Copyright © 成都创新互联科技有限公司重庆分公司  <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备2021005571号</a></div>
            <!--<div class="fr"><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:<a href="https://www.cdcxhl.com/" target="_blank">创新互联</a></div>-->
        </div>
    </div>
    <div class="link">
        <div class="container">
            友情链接::
            <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a>
            <a href="https://www.cdcxhl.com/city/chongqing.html" target="_blank">重庆网站建设</a>
            <a href="">四川网站建设</a>
            <a href="">重庆建设网站</a>
            <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">移动服务器托管</a>
            <a href="http://www.cdfuwuqi.com/" target="_blank">成都服务器托管</a>
            <a href="https://www.cdcxhl.cn/" target="_blank">云服务器</a>
            <a href="http://www.cdhuace.com/" target="_blank">广告设计制作</a>
            <a href="https://www.cdcxhl.com/sheji/chongqing.html" target="_blank">重庆网页设计</a>
            <a href="https://www.cdcxhl.com/zuo/chongqing.html" target="_blank">重庆做网站</a>
            <a href="https://www.cdcxhl.com/zhizuo/chongqing.html" target="_blank">重庆网站制作</a>
            <a href="">重庆网站建设</a>
            <a href="">重庆网站公司</a>
            <a href="">渝中网站制作</a>
            <a href="">重庆网站设计</a>
        </div>
    </div>
</div>
<div class="foot">
    <ul class="public-celan">
        <li>
            <a href="https://p.qiao.baidu.com/cps3/chatIndex?siteToken=6ce441ff9e2d6bedbdfc2a4138de449e&speedLogId=162260383240185e3_1622603832401_02407&eid=6256368&reqParam=%7B%22from%22%3A1%2C%22sessionid%22%3A%22-100%22%2C%22siteId%22%3A%2211284691%22%2C%22tid%22%3A%22-1%22%2C%22userId%22%3A%226256368%22%2C%22ttype%22%3A1%2C%22pageId%22%3A0%7D" target="_blank" class="a1 db tc">
                <img src="/Public/Home/img/icon-23.png" alt="" class="db auto">
                <span class="span-txt">在线咨询</span>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" class="a1 db tc">
                <img src="/Public/Home/img/icon-24.png" alt="" class="db auto">
                <span class="span-txt">电话咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="a1 db tc">
                <img src="/Public/Home/img/icon-25.png" alt="" class="db auto">
                <span class="span-txt">QQ咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=532337155&Site=&Menu=yes" class="a1 db tc public-yuyue-up">
                <img src="/Public/Home/img/icon-26.png" alt="" class="db auto">
                <span class="span-txt">预约顾问</span>
            </a>
        </li>
    </ul>
</div>
<div class="customer">
    <dl class="icon1">
        <dt>
            <a href="tencent://message/?uin=1683211881&Site=&Menu=yes">
                <i class="iconT"><img src="/Public/Home/img/QQ.png" alt=""></i>
                <p>在线咨询</p>
            </a>
        </dt>
    </dl>
    <dl class="icon2">
        <dt><i><img src="/Public/Home/img/weixin.png" alt=""></i><p>微信咨询</p></dt>
        <dd><img src="/Public/Home/img/ewm.png"></dd>
    </dl>
    <dl class="icon3">
        <dt><i><img src="/Public/Home/img/dianhua.png" alt=""></i><p>电话咨询</p></dt>
        <dd>
            <p>028-86922220(工作日)</p>
            <p>18980820575(7×24)</p>
        </dd>
    </dl>
    <dl class="icon4">
        <dt class="sShow">
            <a href="tencent://message/?uin=244261566&Site=&Menu=yes">
                <i><img src="/Public/Home/img/dengji.png" alt=""></i><p>提交需求</p>
            </a>
        </dt>
    </dl>
    <dl class="icon5">
        <dt class="gotop">
            <a href="#top">
                <i><img src="/Public/Home/img/top.png" alt=""></i><p>返回顶部</p>
            </a>
        </dt>
    </dl>
</div>
</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>