建立删除过期状态的存储过程
CREATE
OR
REPLACE
PROCEDURE
Proc_Web_Clearviewstate
IS
/**/ /******************************************************************************
NAME: PROC_WEB_CLEARVIEWSTATE
PURPOSE:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 2006-08-10 1. Created this procedure.
NOTES: 删除过期的页面状态
Automatically available Auto Replace Keywords:
Object Name: PROC_WEB_CLEARVIEWSTATE
Sysdate: 2006-08-10
Date and Time: 2006-08-10, 14:54:17, and 2006-08-10 14:54:17
Username: (set in TOAD Options, Procedure Editor)
Table Name: Web_ViewState
Author: wwwfind
******************************************************************************/
BEGIN
DELETE WEB_VIEWSTATE WHERE Create_Dte < (SYSDATE - 1 / 48 ); // 半个小时前的数据
COMMIT ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL ;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END Proc_Web_Clearviewstate;
/
/**/ /******************************************************************************
NAME: PROC_WEB_CLEARVIEWSTATE
PURPOSE:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 2006-08-10 1. Created this procedure.
NOTES: 删除过期的页面状态
Automatically available Auto Replace Keywords:
Object Name: PROC_WEB_CLEARVIEWSTATE
Sysdate: 2006-08-10
Date and Time: 2006-08-10, 14:54:17, and 2006-08-10 14:54:17
Username: (set in TOAD Options, Procedure Editor)
Table Name: Web_ViewState
Author: wwwfind
******************************************************************************/
BEGIN
DELETE WEB_VIEWSTATE WHERE Create_Dte < (SYSDATE - 1 / 48 ); // 半个小时前的数据
COMMIT ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL ;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END Proc_Web_Clearviewstate;
/
建立JOB
DECLARE
X NUMBER ;
BEGIN
SYS.DBMS_JOB.SUBMIT
( job => X
,what => ' PROC_WEB_CLEARVIEWSTATE; '
,next_date => to_date( ' 02-09-2006 17:38:42 ' , ' dd/mm/yyyy hh24:mi:ss ' )
,interval => ' SYSDATE+30/1440 '
,no_parse => FALSE
);
END ;
/
在Base页中插入下列代码,其余页面继承此页即可
ViewState To DataBase
#region ViewState To DataBase
/**//*
wwwfind 2006/08/10
Blog:http://blog.csdn.net/wwwfind
处理ViewState 将ViewState保存到数据库中,防止过大ViewState在客户端和服务器之间来回传递速度过慢。
在__VIEWSTATE只存储一个ID,该ID为数据库中记录的Primary Key
无效的状态由JOB定期删除
*/
protected override object LoadPageStateFromPersistenceMedium()
...{
object myObj;
if (Request.Form == null)
...{
return null;
}
string str_view = Request.Form["__VIEWSTATE"];
if (str_view == null) return null;
if (myFormat == null) myFormat=new LosFormatter();
try
...{
//获取保存在__VIEWSTATE中的ID
myObj=this.myFormat.Deserialize(str_view);
this.ID=((Triplet)myObj).First.ToString();
//获取保存在数据库中的ViewState
myData.TableName="Web_ViewState";
myData.Fields="ViewState_Txt";
myData.Where="ID_STR='"+this.ID +"'";
str_view=myData.Scalar().ToString();
myObj = this.myFormat.Deserialize(str_view);
}
catch
...{
throw new HttpException(("页面状态丢失,页面已经过期或用户进行非法修改。"));
}
return myObj;
}
protected override void SavePageStateToPersistenceMedium(object viewState)
...{
if (myFormat == null) myFormat=new LosFormatter();
//声称ID标识,如果ID存在默认代表在数据库中已经成功保存该数据
if (this.ID==null)
...{
this.ID=Session.SessionID +this.GetType().Name+DateTime.Now.ToString("yyMMddhhmmss");//ID=Session ID +页面名称+当前时间
//保存VIEWSTATE INSERT
System.IO.StringWriter sw=new System.IO.StringWriter();
this.myFormat.Serialize(sw,viewState);//序列化
//INSERT
myData.Command.CommandText="insert into Web_ViewState(ID_Str,ViewState_Txt,Create_Dte) values('"+this.ID+"',:viewstr,sysDate)";
myData.Command.Parameters.Add(new System.Data.OracleClient.OracleParameter(":viewstr",sw.ToString()));
myData.Command.Connection=myData.Connect;
if (myData.Connect.State!=System.Data.ConnectionState.Open) myData.Connect.Open();
myData.Command.ExecuteNonQuery();
}
else
...{
//保存VIEWSTATE UPDATE
System.IO.StringWriter sw=new System.IO.StringWriter();
this.myFormat.Serialize(sw,viewState);//序列化
//UPDATE
myData.Command.CommandText="update Web_ViewState set ID_Str='"+this.ID +"',ViewState_Txt=:viewstr,Create_Dte=sysdate Where ID_STR='"+this.ID +"'";
myData.Command.Parameters.Add(new System.Data.OracleClient.OracleParameter(":viewstr",sw.ToString()));
myData.Command.Connection=myData.Connect;
if (myData.Connect.State!=System.Data.ConnectionState.Open) myData.Connect.Open();
myData.Command.ExecuteNonQuery();
}
//保存ID到默认的ViewState
((Triplet)viewState).First=this.ID;
((Triplet)viewState).Second=null;
((Triplet)viewState).Third=null;
base.SavePageStateToPersistenceMedium(viewState);
}
//----------------------------------------------------------------------------------------------------------------------------------------------
#endregion
/**//*
wwwfind 2006/08/10
Blog:http://blog.csdn.net/wwwfind
处理ViewState 将ViewState保存到数据库中,防止过大ViewState在客户端和服务器之间来回传递速度过慢。
在__VIEWSTATE只存储一个ID,该ID为数据库中记录的Primary Key
无效的状态由JOB定期删除
*/
protected override object LoadPageStateFromPersistenceMedium()
...{
object myObj;
if (Request.Form == null)
...{
return null;
}
string str_view = Request.Form["__VIEWSTATE"];
if (str_view == null) return null;
if (myFormat == null) myFormat=new LosFormatter();
try
...{
//获取保存在__VIEWSTATE中的ID
myObj=this.myFormat.Deserialize(str_view);
this.ID=((Triplet)myObj).First.ToString();
//获取保存在数据库中的ViewState
myData.TableName="Web_ViewState";
myData.Fields="ViewState_Txt";
myData.Where="ID_STR='"+this.ID +"'";
str_view=myData.Scalar().ToString();
myObj = this.myFormat.Deserialize(str_view);
}
catch
...{
throw new HttpException(("页面状态丢失,页面已经过期或用户进行非法修改。"));
}
return myObj;
}
protected override void SavePageStateToPersistenceMedium(object viewState)
...{
if (myFormat == null) myFormat=new LosFormatter();
//声称ID标识,如果ID存在默认代表在数据库中已经成功保存该数据
if (this.ID==null)
...{
this.ID=Session.SessionID +this.GetType().Name+DateTime.Now.ToString("yyMMddhhmmss");//ID=Session ID +页面名称+当前时间
//保存VIEWSTATE INSERT
System.IO.StringWriter sw=new System.IO.StringWriter();
this.myFormat.Serialize(sw,viewState);//序列化
//INSERT
myData.Command.CommandText="insert into Web_ViewState(ID_Str,ViewState_Txt,Create_Dte) values('"+this.ID+"',:viewstr,sysDate)";
myData.Command.Parameters.Add(new System.Data.OracleClient.OracleParameter(":viewstr",sw.ToString()));
myData.Command.Connection=myData.Connect;
if (myData.Connect.State!=System.Data.ConnectionState.Open) myData.Connect.Open();
myData.Command.ExecuteNonQuery();
}
else
...{
//保存VIEWSTATE UPDATE
System.IO.StringWriter sw=new System.IO.StringWriter();
this.myFormat.Serialize(sw,viewState);//序列化
//UPDATE
myData.Command.CommandText="update Web_ViewState set ID_Str='"+this.ID +"',ViewState_Txt=:viewstr,Create_Dte=sysdate Where ID_STR='"+this.ID +"'";
myData.Command.Parameters.Add(new System.Data.OracleClient.OracleParameter(":viewstr",sw.ToString()));
myData.Command.Connection=myData.Connect;
if (myData.Connect.State!=System.Data.ConnectionState.Open) myData.Connect.Open();
myData.Command.ExecuteNonQuery();
}
//保存ID到默认的ViewState
((Triplet)viewState).First=this.ID;
((Triplet)viewState).Second=null;
((Triplet)viewState).Third=null;
base.SavePageStateToPersistenceMedium(viewState);
}
//----------------------------------------------------------------------------------------------------------------------------------------------
#endregion