Problem ImportWebPart within GetInitialWebParts for Anonymous Users
2006-09-19 09:47
302 查看
转载自:http://forums.asp.net/thread/1067948.aspx
Is there a way to import webparts using WebPartManager.ImportWebPart while not logged in, so I can populate WebPartZones by overriding WebPartZoneBase.GetInitialWebParts with webparts that have been personalized and previously exported with WebPartManager.ExportWebPart
At the moment I’m getting the following error
"Personalization is not enabled and/or modifiable. The Enabled property must be set to true, and a registered personalization provider must be selected. The current user must be granted the right to modify personalization state."
Is there a way to overcome this. Any help would be greatly appreciated.
Thanks
WebPartManager.ImportWebPart() requires personalization to be modifiable, since we assume that ImportWebPart() is only called when a user is adding a dynamic WebPart to the page.
However, you can work around this by writing a custom WebPartManager and WebPartPersonalization to fake it:
public class MyWebPartManager : WebPartManager {
protected override WebPartPersonalization CreatePersonalization() {
return new MyWebPartPersonalization(this);
}
public override WebPart ImportWebPart(System.Xml.XmlReader reader, out string errorMessage) {
((MyWebPartPersonalization)Personalization).Importing = true;
WebPart webPart = base.ImportWebPart(reader, out errorMessage);
((MyWebPartPersonalization)Personalization).Importing = false;
return webPart;
}
}
public class MyWebPartPersonalization : WebPartPersonalization {
public MyWebPartPersonalization(WebPartManager owner)
: base(owner) {
}
internal bool Importing;
protected override IDictionary UserCapabilities {
get {
IDictionary userCapabilities = base.UserCapabilities;
if (Importing) {
userCapabilities[WebPartPersonalization.ModifyStateUserCapability] =
WebPartPersonalization.ModifyStateUserCapability;
}
return userCapabilities;
}
}
}
Is there a way to import webparts using WebPartManager.ImportWebPart while not logged in, so I can populate WebPartZones by overriding WebPartZoneBase.GetInitialWebParts with webparts that have been personalized and previously exported with WebPartManager.ExportWebPart
At the moment I’m getting the following error
"Personalization is not enabled and/or modifiable. The Enabled property must be set to true, and a registered personalization provider must be selected. The current user must be granted the right to modify personalization state."
Is there a way to overcome this. Any help would be greatly appreciated.
Thanks
WebPartManager.ImportWebPart() requires personalization to be modifiable, since we assume that ImportWebPart() is only called when a user is adding a dynamic WebPart to the page.
However, you can work around this by writing a custom WebPartManager and WebPartPersonalization to fake it:
public class MyWebPartManager : WebPartManager {
protected override WebPartPersonalization CreatePersonalization() {
return new MyWebPartPersonalization(this);
}
public override WebPart ImportWebPart(System.Xml.XmlReader reader, out string errorMessage) {
((MyWebPartPersonalization)Personalization).Importing = true;
WebPart webPart = base.ImportWebPart(reader, out errorMessage);
((MyWebPartPersonalization)Personalization).Importing = false;
return webPart;
}
}
public class MyWebPartPersonalization : WebPartPersonalization {
public MyWebPartPersonalization(WebPartManager owner)
: base(owner) {
}
internal bool Importing;
protected override IDictionary UserCapabilities {
get {
IDictionary userCapabilities = base.UserCapabilities;
if (Importing) {
userCapabilities[WebPartPersonalization.ModifyStateUserCapability] =
WebPartPersonalization.ModifyStateUserCapability;
}
return userCapabilities;
}
}
}
相关文章推荐
- get group members and check for users that is not enabled for lync and enable
- Mixture of conda2 and conda3 problem and A guidance of environment set-up for windows users
- for the problem ImportError: cannot import name symbol_database 'text_format'
- unable to get system library for the project" error when import android project to eclips
- import project后,出现Unable to get system library for the project
- for the problem ImportError: cannot import name symbol_database 'text_format'
- appium出现Problem getting session data for driver type AndroidDriver; does it implement 'get driverDat
- import project后,出现Unable to get system library for the project
- aspnet_UsersInRoles_GetRolesForUser
- c:import Unable to get RequestDispatcher for Context
- [转]Content targeting for anonymous users with SharePoint Server 2010(给匿名用户配置外部配置文件)
- import project后,出现Unable to get system library for the project
- Mapped Statements collection does not contain value for com.mybatis_Spring.dao.getAllUsers
- How to get root access for other users with the visudo
- import project后,出现Unable to get system library for the project
- import project后,出现Unable to get system library for the project
- c:import Unable to get RequestDispatcher for Context
- Get Started With Blastwave.org for Solaris 10 Users
- UESTC_Palindromic String 2015 UESTC Training for Search Algorithm & String<Problem M>
- 在同一个jsp页面上即使用字符流,又使用字节流就会出现以下异常:getOutputStream() has already been called for this response