zoukankan      html  css  js  c++  java
  • asp.net配置全局应用程序类 巧妙达到定时生成静态页面

    1. //在项目里添加一个"全局应用程序类(Global Application Class)",在里面写这样的代码:  
    2. public class Global : System.Web.HttpApplication  
    3. {  
    4.     static Timer BuildStaticPagesTimer;  
    5.     static object locker = new object();  
    6.     static int count;  
    7.   
    8.     protected void Application_Start(object sender, EventArgs e)  
    9.     {  
    10.         //double check lock...  
    11.         if (BuildStaticPagesTimer == null)  
    12.         {  
    13.             lock (locker)  
    14.             {  
    15.                 if (BuildStaticPagesTimer == null)  
    16.                 {  
    17.                     //every 20 minutes, run BuildStaticPagesTimer_Callback in every 20 minutes  
    18.                     BuildStaticPagesTimer = new Timer(BuildStaticPagesTimer_Callback, null, 0, 20 * 60 * 1000);  
    19.                 }  
    20.             }  
    21.         }  
    22.     }  
    23.   
    24.     private static void BuildStaticPagesTimer_Callback(object state)  
    25.     {  
    26.         Dictionary<stringstring> urlsNeedToBuild = GetPagesNeedToBuiltStatic();  
    27.         foreach (string oldUrl in urlsNeedToBuild.Keys)  
    28.         {  
    29.             string newUrl = urlsNeedToBuild[oldUrl];  
    30.             Build(oldUrl, newUrl);  
    31.         }  
    32.     }  
    33.   
    34.     private static void Build(string oldUrl, string newUrl)  
    35.     {  
    36.         //在这里写生成静态页面的代码  
    37.         throw new NotImplementedException();  
    38.     }  
    39.   
    40.     private static Dictionary<stringstring> GetPagesNeedToBuiltStatic()  
    41.     {  
    42.         //在这里判断哪些页面需要生成静态页面  
    43.         throw new NotImplementedException();  
    44.     }  
    45. }  
  • 相关阅读:
    typeOf操作符及数据类型
    图片轮播 js
    百度地图API学习
    jq 使页脚固定在底部
    js 动态自动添加 删除
    background-size 兼容ie8以下浏览器的方法
    opacity css3 ie8以下兼容方法
    ie 6、7/position: absolute bug解决方法
    IE 下的rgba背景透明
    2017腾讯实习生春招前端初面总结
  • 原文地址:https://www.cnblogs.com/codeloves/p/3338675.html
Copyright © 2011-2022 走看看