Shoud I give up to determine user role programtically????

From: TJ (TJ_at_discussions.microsoft.com)
Date: 09/10/04


Date: Thu, 9 Sep 2004 20:29:01 -0700

Hi,

I am developing one web part that needs to show the site role of current
user..
Here is my code.

Impersonator i = null;
try
{
         i = new Impersonator("administrator", "mydomain", "mypassword);

        if(i.Impersonate())
        {

        SPWeb currentWeb = SPControl.GetContextWeb(this.Context);
        SPRoleCollection currentRoles = currentWeb.CurrentUser.Roles;

        foreach(SPRole myRole in currentRoles)
        {
                          output.Write("Current Role: " +
SPEncode.HtmlEncode(myRole.Name.ToString()) + " <BR> " );
        }
         
      }
catch(Exception exp)
{
            output.WriteLine("Failed: " + exp.Message);
}
finally
{
         if (i != null)
        {
             i.Undo();
        }
}

I tried everything such as giving the full-trust and impersonation.....but
no lucks at all....
When administrator logs in, the role was displayed correctly on the web
part...
However, if non-administrator logs in, login dialog box keeps poping up, and
then finally error message says that

Access denied. You do not have permission to perform this action or access
this resource.
Access requests are not enabled.

I really do not have any idea why it didn't work at all....

As I said, giving full-trust and impersonation that I tried every possible
things to work for this code, however, I coud't make this code working...
What am I missing for this issue???

Thank you in advance.

...................................................................TJ



Relevant Pages

  • How to determine user role of the current user programatically
    ... I am developing one web part that needs to show the site role of current ... Impersonator i = null; ... When administrator logs in, the role was displayed correctly on the web ... giving full-trust and impersonation that I tried every possible ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: How to determine user role of the current user programatically
    ... SPWeb oWeb = oSite.OpenWeb; ... > I am developing one web part that needs to show the site role of current ... > When administrator logs in, the role was displayed correctly on the web ... giving full-trust and impersonation that I tried every possible ...
    (microsoft.public.sharepoint.portalserver.development)