自定义个性化提供程序 - 实现 FindState 方法
我一直为此伤透了脑筋。我很感激任何帮助。
我有一个自定义 PersonalizationProvider、自定义 WebPartManager 和自定义 WePart 类。我有自定义数据表,用于存储每个用户的个性化数据。我的任务是以编程方式循环访问每个用户添加的所有 Web 部件,以便我可以设置个性化属性。
根据文档,FindState 方法返回给定 PersonalizationStateQuery 的 PersonalizationStateInfoCollection:
PersonalizationStateQuery pq = new PersonalizationStateQuery();
pq.PathToMatch = path;
pq.UsernameToMatch = userName;
int count;
CustomPersonalizationProvider provider= new CustomPersonalizationProvider();
PersonalizationStateInfoCollection pcol = provider.FindState(PersonalizationScope.User, pq, 0, Int32.MaxValue, out count);
PersonalizationProvider 是一个抽象类,我必须在自定义类中为 FindState 方法提供自己的实现。我花了 6 个小时试图找到一些东西,但我不知道如何实现这个方法。
PersonalizationData 是 blob。我可以将它反序列化为对象数组。但仅此而已。我不知道如何将该 blob 序列化/反序列化到 PersonalizationStateInfoCollection。
String BlobString = Convert.ToBase64String(UserDataBlob);
ObjectStateFormatter formatter = new ObjectStateFormatter();
Object[] DeserializedObjects = (Object[])formatter.Deserialize(BlobString);
有谁知道 WebPartManager 如何将 UserPersonalizationData 序列化到存储在数据库中的字节数组中?
I have been breaking my head over this. I appreciate any help.
I have a custom PersonalizationProvider, custom WebPartManager and custom WePart class. I have custom data tables for storing the Personalization Data per user. My task is to programmtically loop through all the web parts added by each user so that I can set a personalizable attribute.
According to the documentation, FindState method returns a PersonalizationStateInfoCollection for a given PersonalizationStateQuery:
PersonalizationStateQuery pq = new PersonalizationStateQuery();
pq.PathToMatch = path;
pq.UsernameToMatch = userName;
int count;
CustomPersonalizationProvider provider= new CustomPersonalizationProvider();
PersonalizationStateInfoCollection pcol = provider.FindState(PersonalizationScope.User, pq, 0, Int32.MaxValue, out count);
PersonalizationProvider is an abstract class and I will have to provide my own implementation for the FindState method in my custom class. I have spent last 6 hours trying to find something and I don't know how to implement this method.
The PersonalizationData is blob. I could deserialize it to object array. But nothing further. I have no idea how to serialize/deserialize that blob in to PersonalizationStateInfoCollection.
String BlobString = Convert.ToBase64String(UserDataBlob);
ObjectStateFormatter formatter = new ObjectStateFormatter();
Object[] DeserializedObjects = (Object[])formatter.Deserialize(BlobString);
Does anyone know how WebPartManager serializes the UserPersonalizationData in to the byte array that is stored in the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从 SQLPersonalizationProvider 而不是 PersonalizationProvier 继承您的提供程序。这样您就不必实现 FindState、ResetState、ReserUserState 和 GetCountOfState 方法。
几个月前,我试图解码这些字节,但当我发现我实际上不必使用这个技巧来编写它时,我放弃了。
但我认为这不是一个完美的解决方案。如果您的提供商使用 Oracle、MySql 或除 SQL Server 之外的任何其他产品,您会发现在调用个性化提供商的 Initialize 方法后,它将开始请求数据库中的 aspnet 标准存储过程。
Try inherit your provider from SQLPersonalizationProvider instead of PersonalizationProvier. This way you don´t have to implement the FindState, ResetState, ReserUserState and GetCountOfState methods.
Several months ago I was trying to decode those bytes, but I gave up when I discovered that I didn´t really have to write it using this trick.
But I'm thinking that's not a perfect solution. If your provider use Oracle, MySql or anything but SQL Server, you'll find that after calling the Initialize method of your personalization provider, it will start to ask for the aspnet standard stored procedures in the database.
该实施指南对我有用 - http://www.codeproject.com/Questions/83150/ SqlPersonalizationProvider-方法
This implementation guide worked for me - http://www.codeproject.com/Questions/83150/SqlPersonalizationProvider-Methods