关于静态页自动生成
我尝试了在Global.asax文件中定时执行程序
但是虚拟路径的问题给我卡住了
谁有成功的经验可以传授下
希望大哥们成功过再说。。别到处复制黏贴 谢谢。。。
[解决办法]
就是替换标签
[解决办法]
帮顶!
[解决办法]
public class BuilderHtml { public string RootUrl = WebUnits.WebRootUrl; public static string Serverpath = HttpContext.Current.Server.MapPath("/"); public void StartAutoBuilder() { WriteLog(string.Format("StartAutoBuilder")); ThreadStart threadStart = new ThreadStart(AutoBuilder); Thread th = new Thread(threadStart); th.Start(); } /// < summary> ///10分钟生成一次 /// < /summary> public void AutoBuilder() { int fasterBuilderTime = Int32.Parse(ConfigurationSettings.AppSettings["FasterBuilderTime"]); Thread.Sleep(fasterBuilderTime); BuildMethod(); } private void BuildMethod() { int sleepTime = Int32.Parse(ConfigurationSettings.AppSettings["BuilderTime"]); while (true) { Thread.Sleep(sleepTime); BuildAllHtmlPage(); } } /// <summary> /// 生成模块首页静态页面 /// </summary> public void BuildAllHtmlPage() { ThreadStart threadStart = new ThreadStart(BuildHtmlPage); Thread th = new Thread(threadStart); th.Start(); } private void BuildHtmlPage() { string[] htmlPages = ConfigurationSettings.AppSettings["HomeHtml"].ToString().Split(';'); for (int i = 0; i < htmlPages.Length; i++) { string config = htmlPages[i]; string[] arr = config.Split(','); string url = RootUrl + arr[0]; string filePath = Serverpath + arr[1]; try { DBResult result = HtmlBuilder.CreateHtml(url, filePath); if (!result.Succeed) WriteLog(string.Format("生成失败:{0},{1},原因:{2}", url, filePath, result.Message)); } catch (Exception ex) { WriteLog(string.Format("生成失败:{0},{1},原因:{2}", url, filePath, ex.Message)); } } } public static void WriteLog(string log) { try { string fileName = Serverpath + "log.txt"; if (File.Exists(fileName)) { using (StreamWriter sw = new StreamWriter(fileName, true)) { sw.WriteLine( string.Format("\r\n==[{0}]===================================\r\n{1}", DateTime.Now, log)); sw.Close(); } } } catch (Exception ) { } } }