Accessing SPRole class returns an access denied exception

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Martin Cabalzar (m.cabalzar_at_gmx.ch)
Date: 02/17/04


Date: Tue, 17 Feb 2004 13:17:11 +0100

Hello

Does anybody know the reason, why accessing the SPUser.Roles method gives an
"access denied" exception, altough the current user is impersonated as
administrator? All other operations where you have to impersonate as
administrator works without problems, only the SPRoleCollection and SPRole
classes makes trouble.

This is the exception:

Microsoft.SharePoint.Library.SPRequestInternalClass.GetGroupsDataAsSafeArray
(String bstrUrl, UInt32 dwGroupsScope, Boolean fIsGlobal, String bstrValue,
UInt32& pdwColCount, UInt32& pdwRowCount, Object& pvarDataSet)
at Microsoft.SharePoint.Library.a.a(String A_0, UInt32 A_1, Boolean A_2,
String A_3, UInt32& A_4, UInt32& A_5, Object& A_6)
at Microsoft.SharePoint.SPGroupCollection.a(Boolean A_0, String[] A_1)
at Microsoft.SharePoint.SPGroupCollection.g()
at Microsoft.SharePoint.SPGroupCollection.Undirty()
at Microsoft.SharePoint.SPRoleCollection.Undirty()
at
Microsoft.SharePoint.SPBaseCollection.System.Collections.IEnumerable.GetEnum
erator()
at MyWebParts.MyDocuments.ListsForCurrentUser(SPBaseType listType)

I don't think the problem is the impersonation, because all other functions
works.

This is the basic code:

SPUser user = SPControl.GetContextWeb(Context).CurrentUser;
SPRoleCollection roleCollection = user.Roles;
foreach(SPRole role in roleCollection){
  output.Write(role.Name);
}

Thank you for help!
Martin



Relevant Pages

  • Re: Sql Reporting Serviced - > ASP.NET ACCESS DENIED!
    ... The account you are logging in to when on the server doesn't have the ... do you have <Impersonate> set to True? ... > Exception Details: System.UnauthorizedAccessException: Access to the path ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Failed to start monitoring file changes when impersonation="true".
    ... With impersonate = true, the thread takes the identity of either: ... An unhandled exception occurred during the execution of the ... Failed to start monitoring file ... I also tried to give full access control to my ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How can a user impersonate an adminstrator
    ... But only if you are connecting to a remote computer, ... You can not impersonate an administrator on the "local" computer without ...
    (microsoft.public.win32.programmer.wmi)
  • Impersonation using WindowsIdentity( upn ) ctor
    ... I'm trying to impersonate a user using the WindowsIdentity ctor. ... An unhandled exception occurred during the execution of the ... * The app pool for the virtual dir is configured with Network Service ...
    (microsoft.public.dotnet.security)
  • Impersonation using WindowsIdentity( upn ) ctor
    ... I'm trying to impersonate a user using the WindowsIdentity ctor. ... An unhandled exception occurred during the execution of the ... * The app pool for the virtual dir is configured with Network Service ...
    (microsoft.public.dotnet.framework.aspnet.security)