由于viewstate太大了,现在能做的就是优化,还有一些控件禁止了viewstate,各位还有没有别的招~~~
解决方案 »
- ASP.NET 页面中的数据导出Excel
- 事物 添加操作 如何获取自动增长的ID
- 发布问题,请指教
- 一Request.Cookies["username"].Value.ToString(),调试就完全结束到IE界面上去是怎么回事?
- 一段简短的后台登录代码并将登录信息写入数据库一点小问题,请高手进来看看!
- 刚开始接触2.0 发现基础问题~
- 问一个XML显示数据问题,有点想不通,高分酬谢!
- asp.net 中使用Repeater控件
- 请问 radiobuttonlist 的值怎么取?????
- linkButton
- VS2008的BUG!有图有真相!
- 伪URL Context.Server.Execute 出错
using System.IO;
using System.Web.UI;public class XVPage : Page
{
static private DirectoryInfo _Dir; private DirectoryInfo Dir
{
get
{
if (_Dir == null)
{
_Dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data"));
if (!_Dir.Exists)
_Dir.Create();
_Dir = new DirectoryInfo(Path.Combine(_Dir.FullName, "ViewState"));
if (!_Dir.Exists)
_Dir.Create();
}
return _Dir;
}
} protected override object LoadPageStateFromPersistenceMedium()
{
PageStatePersister ps = this.PageStatePersister;
ps.Load();
if (ps.ControlState != null)
ps.ControlState = 反序列化对象((string)ps.ControlState);
if (ps.ViewState != null)
ps.ViewState = 反序列化对象((string)ps.ViewState);
return new Pair(ps.ControlState, ps.ViewState);
} protected override void SavePageStateToPersistenceMedium(object state)
{
PageStatePersister ps = this.PageStatePersister;
if (state is Pair)
{
Pair pair = (Pair)state;
ps.ControlState = pair.First;
ps.ViewState = pair.Second;
}
else
{
ps.ViewState = state;
}
if (ps.ControlState != null)
ps.ControlState = 序列化对象(ps.ControlState);
if (ps.ViewState != null)
ps.ViewState = 序列化对象(ps.ViewState);
ps.Save();
} private object 反序列化对象(string stateID)
{
string stateStr = (string)Cache[stateID];
string file = Path.Combine(Dir.FullName, stateID);
if (stateStr == null)
stateStr = File.ReadAllText(file);
else
Cache.Remove(stateID);
return new ObjectStateFormatter().Deserialize(stateStr);
} private string 序列化对象(object obj)
{
string value = new ObjectStateFormatter().Serialize(obj);
string stateID = (DateTime.Now.Ticks + (long)value.GetHashCode()).ToString(); //产生离散的id号码
File.WriteAllText(Path.Combine(Dir.FullName, stateID), value);
Cache.Insert(stateID, value);
return stateID;
} protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
DateTime dt = DateTime.Now.AddMinutes(-20);
foreach (FileInfo fl in Dir.GetFiles())
if (fl.LastAccessTime < dt)
try
{
fl.Delete();
}
catch
{
}
}
}