Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Code Access Security? Or user's permissions?

  Asked By: Dane    Date: Feb 22    Category: Sharepoint    Views: 1440

I have a problem with running a very simple webpart.
(I have similar problems with an other webpart.)

I created a strong named webpart and registered it in the BIN and set
the trust=WSS_Medium.

The only code I added to the template is in the 'RenderWebPart(). Beside
some output.write statements.:
SPSite spSite = SPControl.GetContextSite(Context);
SPWeb spWeb = spSite.OpenWeb();
SPRoleCollection spRoleCollection = spWeb.CurrentUser.Roles;

foreach (SPRole userMembership in spRoleCollection)
userGroupMemberships = userGroupMemberships +
SPEncode.HtmlEncode(userMembership.Name) + " ";
If I run this webpart as administrator all goes well.
If I run the webpart with an account that is a Contributor I'm prompted
for a username&password.
If I remove the foreach statement, the Contributor is allowed to this

The webpart behaves exactly the same when placed in the GAC

My conclusion is the Contributor has no richt to inquire the
spWeb.CurrentUser.Roles objects.
How do I grant him these rights? (Of course only for THIS WebPart and
not make him an administrator.)

What am I doing wrong or have I forgotten?



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on Code Access Security? Or user's permissions? Or get search suggestion and latest updates.