日期:2014-05-20 浏览次数:20382 次
protected override object LoadPageStateFromPersistenceMedium() { var viewStateID = (string)((Pair)base.LoadPageStateFromPersistenceMedium()).Second; var stateStr = (string)Cache[viewStateID]; if (stateStr == null) { var fn = Path.Combine(this.Request.PhysicalApplicationPath, @"App_Data/ViewState/" + viewStateID); stateStr = File.ReadAllText(fn); } return new ObjectStateFormatter().Deserialize(stateStr); } protected override void SavePageStateToPersistenceMedium(object state) { var value = new ObjectStateFormatter().Serialize(state); var viewStateID = (DateTime.Now.Ticks + (long)this.GetHashCode()).ToString(); //产生离散的id号码 var fn = Path.Combine(this.Request.PhysicalApplicationPath, @"App_Data/ViewState/" + viewStateID); ThreadPool.QueueUserWorkItem(obj => File.WriteAllText(fn, value)); Cache.Insert(viewStateID, value); base.SavePageStateToPersistenceMedium(viewStateID); }
protected void Application_Start(object sender, EventArgs e) { var dir = new DirectoryInfo(this.Server.MapPath("~/App_Data/ViewState/")); if (!dir.Exists) dir.Create(); else { var nt = DateTime.Now.AddHours(-1); dir.GetFiles().ForEach(f => { if (f.CreationTime < nt) f.Delete(); }); } }