Custom WebPartManager

WebPartPersonalization Class  

C#
[TypeConverterAttribute(typeof(EmptyStringExpandableObjectConverter))] 
public class WebPartPersonalization
 

This class implements the logic required to carry out lower-level personalization operations. Although the

If you use the default implementation of the WebPartManager, it creates an instance of the WebPartPersonalization class that you can use by referencing the Personalization property. For example, to access the InitialScope property, you would specify WebPartManager.Personalization.InitialScope.

Notes to Inheritors: The WebPartPersonalization class works closely with a WebPartManager control and the rest of the personalization infrastructure. The default implementation of personalization is a very robust subsystem that should meet your personalization needs. In most cases, if you want to customize personalization, you can create a data provider for use as a personalization provider by creating a class that inherits from PersonalizationProvider. If you want to create a personalization subsystem significantly different from that provided by the WebPartPersonalization and the WebPartManager classes, you should create a custom WebPartPersonalization implementation by deriving from WebPartPersonalization and add your own custom logic. Then create a custom WebPartManager implementation by deriving from WebPartManager, add your own custom logic, and override the CreatePersonalization method to return your custom WebPartPersonalization implementation. Because a WebPartManager control makes requests to the personalization infrastructure by way of a WebPartPersonalization instance, the WebPartManager control does not directly interact with or hold references to PersonalizationProvider implementations.

WebPartManager class manages the high-level life cycle of personalization, it is the WebPartPersonalization class that is responsible for actually implementing the physical steps necessary to carry out specific personalization actions. The WebPartPersonalization class in turn relies on an implementation of PersonalizationProvider to communicate with the underlying data store for personalization information.
 
转载自:http://forums.asp.net/thread/1067948.aspx
 
 
 
 
Re: PortalFramework does not use virtual (mapped) URL's
Stefan:

There are only two things you forgot to mention ;) The SqlPeronslaizationProvider is sealed in the latest CTP build of ASP.Net. Hopefully this will not be sealed when beta 2 is released!?

A new custom WebPartPersonalization class must also be created where the HasPersonalizationState method must be override and also pass the Request.RawUrl to the providers GetCountOfState method.

Because there must be a new WebpartPersonalization class, there must also be a new custom WebPartManager class where the CreatePersonalization method is override and returns the new custom WebPartPersonalization class:

Custom WebPartManager:


public class MyWebPartManager : WebPartManager
{
public MyWebPartManager()
{
}

protected override WebPartPersonalization CreatePersonalization()
{
return new Nsquared2WebPartPersonalization(this);
}
}


Custom WebPartPersonalization:


public class Nsquared2WebPartPersonalization : WebPartPersonalization
{
private PersonalizationProvider _provider;


public Nsquared2WebPartPersonalization(WebPartManager owner) : base(owner)
{
}


public override bool HasPersonalizationState
{
get
{
if (this._provider == null)
throw new InvalidOperationException("Can't use the WebPartPersonalization's HasPersonalizationState before Page_Init");

if (this.WebPartManager.Page == null)
throw new InvalidOperationException("The WebPartManager.Page property can not be null");

HttpRequest request = this.WebPartManager.Page.Request;
if (request == null)
throw new InvalidOperationException("The WebPartManager.Page.Request property can not be null");

PersonalizationStateQuery query = new PersonalizationStateQuery();

query.PathToMatch = request.RawUrl;

if ((this.Scope == PersonalizationScope.User) && request.IsAuthenticated)
query.UsernameToMatch = this.WebPartManager.Page.User.Identity.Name;

return (this._provider.GetCountOfState(this.Scope, query) > 0);
}
}


private void DeterminePersonalizationProvider()
{
if (string.IsNullOrEmpty(this.ProviderName))
{
this._provider = PersonalizationAdministration.Provider;
}
else
{
PersonalizationProvider provider = PersonalizationAdministration.Providers[this.ProviderName];
if (provider == null)
{
throw new ProviderException(string.Format("Can't found provider '{0}'", this.ProviderName));
}
this._provider = provider;
}
}


protected override PersonalizationScope Load()
{
if (!this.Enabled)
throw new InvalidOperationException("Personalization not enabled");

this.DeterminePersonalizationProvider();

return base.Load();
}

....
}


Custom SqlPersonalizationProvider (When it's not sealed ;) )


public class Nsquared2SqlPersonalizationProvider : SqlPersonalizationProvider
{

private string GetPath(WebPartManager webPartManager)
{
if (webPartManager == null)
throw new ArgumentNullException("webPartManager");

if (webPartManager.Page == null)
throw new ArgumentException("The webPartManager's Page property can not be Null");

HttpRequest request = webPartManager.Page.Request;
if (request == null)
throw new ArgumentException("The webPartManager's Page.Request property can not be Null");

path = request.RawUrl;
}


protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
{
base.LoadPersonalizationBlobs(webPartManager, this.GetPath(webPartManager), userName, sharedDataBlob, userDataBlob);
}

protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
{
base.ResetPersonalizationBlob(webPartManager, this.GetPath(webPartManager), userName, sharedDataBlob, userDataBlob);
}

protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
{
base.ResetPersonalizationBlob(webPartManager, this.GetPath(webPartManager), userName, sharedDataBlob, userDataBlob);
}
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值