zoukankan      html  css  js  c++  java
  • .net 动态页面生成静态页面


    .net 动态页面生成静态页面的方法大体可以分为三种

    1.url重写,只是链接地址换了(伪静态)

      <1> 在bin中添加引用

            URLRewriter.pdb
            URLRewriter.dll

      <2> 在web.config中的配置

             添加<system.web>                 

                       <httpModules>
                           <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>

                      </httpModules>

              </system.web>

             

        <configSections>
           <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/> 

        </configSections>

    <RewriterConfig>
            <Rules>
                <RewriterRule>
                    <LookFor>~/index\.html</LookFor><!--要显示的文件名称-->
                    <SendTo>~/index.aspx</SendTo><!--要替换的文件名称-->
                </RewriterRule>
            
            </Rules>
        </RewriterConfig>
     

             


    2.使用模板生成静态页面

    3.动态页面直接生成静态页面

    //url:动态页面的地址

    //savefile:要生成的晶体页面的地址

     private void ToHTML(string url,string savefile)
         {
             WebClient wc = new WebClient();
             byte[] bs = wc.DownloadData(url);
             string html = Encoding.GetEncoding("utf-8").GetString(bs);        
             string saveFile = Server.MapPath(savefile);
             StreamWriter sw = new StreamWriter(saveFile, false, Encoding.GetEncoding("utf-8"));
             sw.Write(html);
             sw.Close();
             Response.Write("恭喜,页面已经生成");
        }

  • 相关阅读:
    [LeetCode] 210. Course Schedule II
    [LeetCode] 207. Course Schedule
    [LeetCode] 450. Delete Node in a BST
    [LeetCode] 1122. Relative Sort Array
    [LeetCode] 1013. Partition Array Into Three Parts With Equal Sum
    [LeetCode] 173. Binary Search Tree Iterator
    [LeetCode] 208. Implement Trie (Prefix Tree)
    [LeetCode] 211. Add and Search Word
    [LeetCode] 449. Serialize and Deserialize BST
    [LeetCode] 236. Lowest Common Ancestor of a Binary Tree
  • 原文地址:https://www.cnblogs.com/feifei/p/2133401.html
Copyright © 2011-2022 走看看