asp.net配置全局应用程序类 巧妙达到定时生成静态页面

2016-12-30 09:57:18来源:oschina作者:深圳大道人点击

第七城市
//在项目里添加一个"全局应用程序类(Global Application Class)",在里面写这样的代码:
public class Global : System.Web.HttpApplication
{
static Timer BuildStaticPagesTimer;
static object locker = new object();
static int count;
protected void Application_Start(object sender, EventArgs e)
{
//double check lock...
if (BuildStaticPagesTimer == null)
{
lock (locker)
{
if (BuildStaticPagesTimer == null)
{
//every 20 minutes, run BuildStaticPagesTimer_Callback in every 20 minutes
BuildStaticPagesTimer = new Timer(BuildStaticPagesTimer_Callback, null, 0, 20 * 60 * 1000);
}
}
}
}
private static void BuildStaticPagesTimer_Callback(object state)
{
Dictionary urlsNeedToBuild = GetPagesNeedToBuiltStatic();
foreach (string oldUrl in urlsNeedToBuild.Keys)
{
string newUrl = urlsNeedToBuild[oldUrl];
Build(oldUrl, newUrl);
}
}
private static void Build(string oldUrl, string newUrl)
{
//在这里写生成静态页面的代码
throw new NotImplementedException();
}
private static Dictionary GetPagesNeedToBuiltStatic()
{
//在这里判断哪些页面需要生成静态页面
throw new NotImplementedException();
}
}
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台