Sunday, June 19, 2011

Show webpart custom property (PersonalizationScope.User) for Contribute users

Weeks ago in a project I added several custom webparts with one or more of the following custom properties:

[Category("Guisu properties")]
[Personalizable(PersonalizationScope.User)]
[WebDisplayName("Show Company")]
[WebBrowsable(true)]
public bool ShowCompany
{
get
{
return showCompany;
}
set
{
showCompany = value;
}
}


My idea was to have different levels of accessing these properties, so the administrator could see ALL the properties, including those with PersonalizationScope.Shared, and the users with Contribute permissions could only see the properties with PersonalizationScope.User. Moreover, according to MSDN, these properties should be user-specific.

Cool, huh? Well, it is not so easy. Thanks to this entry in http://akifkamalsyed.wordpress.com/ blog, I realized it is necessary to change several SafeControl entries.

This could be a problem for deployments... if we did not have the safe control entries configuration in VS2010 :) So the normal SafeControl properties for a default webpart are shown like this:




Just change them to the following configuration, redeploy, and it should work:

No comments:

Post a Comment