虽然DNN中有个
DiskPageStatePersister,可是在Host Setting中不可以选择,而且我自己测试了下,有Bug,有时候文件名太长了,不能建立文件。那在不该DNN source code的前提下怎么才能把viewstate保存在服务器端呢? 让我们先研究下DNN的PageBase中的
PageStatePersister属性:
Protected
Overrides
ReadOnly
Property
PageStatePersister()
As
System.Web.UI.PageStatePersister
Get
'
Set ViewState Persister to default (as defined in Base Class)
Dim
_persister
As
PageStatePersister
=
MyBase
.PageStatePersister
If
Not
DotNetNuke.Common.Globals.HostSettings(
"
PageStatePersister
"
)
Is
Nothing
Then
Select
Case
DirectCast
(DotNetNuke.Common.Globals.HostSettings(
"
PageStatePersister
"
),
String
)
Case
"
M
"
_persister
=
New
CachePageStatePersister(
Me
)
Case
"
D
"
_persister
=
New
DiskPageStatePersister(
Me
)
Case
"
S
"
_persister
=
New
SessionPageStatePersister(
Me
)
End
Select
End
If
Return
_persister
End
Get
End Property
从上面的Code中我们看到,DNN只handle "M", "D", "S"这几种,如果把viewstate保存在Page中的话,就会用.Net 默认的PageStaePersister.
接下来,我们打开Reflector看看System.Web.UI.Page是怎么写的:
protected
virtual
PageStatePersister PageStatePersister{
get
{
if
(
this
._persister
==
null
) { PageAdapter pageAdapter
=
this
.PageAdapter;
if
(pageAdapter
!=
null
) {
this
._persister
=
pageAdapter.GetStatePersister(); }
if
(
this
._persister
==
null
) {
this
._persister
=
new
HiddenFieldPageStatePersister(
this
); } }
return
this
._persister; }}
好了,我们可以看到,原来会先从PageAdapter中拿,如果找不到的话,才会用:
HiddenFieldPageStatePersister.
这样我们就可以从PageAdapter下手了。
首先PageApater:
public
class
HCPageAdapter : PageAdapter {
public
override
PageStatePersister GetStatePersister() {
return
new
XmlPageStatePersister(
base
.Page); } }
其中:
XmlPageStatePersister的任务就是save, Load Viewstate From server disk.
然后的.Browser文件,告诉.Net要加载
HCPageAdapter
<
browsers
>
<
browser
refID
="Default"
>
<
controlAdapters
>
<
adapter
controlType
="DotNetNuke.Framework.PageBase"
adapterType
="HC.DNN.Services.ViewState.HCPageAdapter"
/>
</
controlAdapters
>
</
browser
>
</
browsers
>
Ok, 现在编译,把dll放到bin folder, .Browser文件放到App_browser folder就完成了, 这样即使下载升级DNN也不影响。
你可以从这里下载本文用到的Code:
DNN store Viewstate in disk revised
转载于:https://www.cnblogs.com/isc00028/archive/2009/10/03/1577694.html