189 8069 5689

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://cdxtjz.cn/article/pgcios.html">http://cdxtjz.cn/article/pgcios.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dejdsgc.html">路由器怎么连接到网络 路由器怎么连接网络电视接口使用</a>
                </li><li>
                    <a href="/article/dejdsej.html">c语言编写日志输出函数 c语言日志模块</a>
                </li><li>
                    <a href="/article/dejdsjc.html">c语言用函数找最大值 c语音求最大值的函数</a>
                </li><li>
                    <a href="/article/dejdsse.html">包含md5算法java代码的词条</a>
                </li><li>
                    <a href="/article/dejdsci.html">并查集JAVA代码 javabus查询</a>
                </li>        </ul>
    </div>
</div>
<footer>
  <div class="foot container">
    <div class="footl fl">
      <h3>联系我们</h3>
      <dl>
        您好HELLO!<br>
        感谢您来到成都网站建设公司,若您有合作意向,请您为我们留言或使用以下方式联系我们,

        我们将尽快给你回复,并为您提供真诚的设计服务,谢谢。
      </dl>
      <ul>
        <li>电话:028- <span>86922220 18980695689</span></li>
        <li>商务合作邮箱:631063699@qq.com</li>
        <li>合作QQ: 532337155</li>
        <li>成都网站设计地址:成都市青羊区锣锅巷31号五金站写字楼6楼</li>
      </ul>
    </div>
    <div class="footr fr">
      <h3>小谭建站工作室</h3>
      <dl>
        成都小谭网站建设公司拥有多年以上互联网从业经验的团队,始终保持务实的风格,以"帮助客户成功"为已任,专注于提供对客户有价值的服务。

        我们已为众企业及上市公司提供专业的网站建设服务。我们不只是一家网站建设的网络公司;我们对营销、技术、管理都有自己独特见解,小谭建站采取“创意+综合+营销”一体化的方式为您提供更专业的服务!
      </dl>
      <h3>小谭观点</h3>
      <dl>
        相对传统的成都网站建设公司而言,小谭是互联网中的网站品牌策划,我们精于企业品牌与互联网相结合的整体战略服务。<br>
        我们始终认为,网站必须注入企业基因,真正使网站成为企业vi的一部分,让整个网站品牌策划体系变的深入而持久。
      </dl>
    </div>
  </div>
  <div class="link">
    <div class="container"> 
        <span> 友情链接:</span>
        <a href="http://www.lzgulin.com/" title="四川正泰动物" target="_blank">四川正泰动物</a>   <a href="https://www.scvps.cn/" title="服务器租用" target="_blank">服务器租用</a>   <a href="http://www.cdhuace.com/fuwu.html" title="成都名片印刷厂" target="_blank">成都名片印刷厂</a>   <a href="http://www.zaowang.cn/" title="SF双层罐" target="_blank">SF双层罐</a>   <a href="http://www.pxwzjz.com/" title="蓬溪网站建设" target="_blank">蓬溪网站建设</a>   <a href="http://www.cdxwcx.cn/" title="成都网站设计" target="_blank">成都网站设计</a>   <a href="https://www.cdcxhl.com/xiangyingshi.html" title="成都响应式网站建设公司" target="_blank">成都响应式网站建设公司</a>   <a href="http://www.cdxwcx.cn/tuoguan/ershu.html" title="中国电信成都枢纽中心" target="_blank">中国电信成都枢纽中心</a>   <a href="http://www.scyingshan.cn/" title="营山网站建设" target="_blank">营山网站建设</a>   <a href="http://www.cdxwcx.cn/sheji/" title="网站设计公司" target="_blank">网站设计公司</a>     
    </div>
  </div>
  <div class="copy"> © Copyright 2023 <a href="http://www.cdxtjz.cn/">小谭建站工作室</a>All Rights Reserved.  <a href="http://beian.miit.gov.cn" target="_blank" rel="nofollow">蜀ICP备2021004003号-2</a>  <a href="https://www.cdxwcx.com" target="_blank">成都网站建设</a> / <a href="https://www.cdxwcx.com" target="_blank">成都网站建设</a> / <a href="https://www.cdxwcx.com" target="_blank">响应式网站建设</a> / <a href="https://www.cdxwcx.com target=" _blank"="">定制网站建设</a>  <a href="sitemap.xml" target="_blank">xml</a> <a href="sitemap.html" target="_blank">网站地图</a> </div>
</footer>
</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>