Album Permissions - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Album Permissions

  • Album Permissions
  • I'm working on a new control and want to upload images to an album for all users.  I have tried this code to programatically set the permission to allow everyone manage permissions so they can upload images:

    var album = App.WorkWith()
    LibrariesManager manager = LibrariesManager.GetManager();
    var roleId = SecurityManager.ApplicationRoles["Everyone"].Id;
    Telerik.Sitefinity.Security.Model.Permission permissionForEveryone = album.GetActivePermissions().Where(p => p.PrincipalId == roleId && p.ObjectId == album.Id).FirstOrDefault();
    if (permissionForEveryone == null)
        permissionForEveryone = manager.CreatePermission(SecurityConstants.Sets.Image.Manage, album.Id, roleId);
    permissionForEveryone.GrantActions(true, SecurityConstants.Sets.Image.View);

    After spending some time trying to get that to work I used the Admin and set the manage permissions manually and gave everyone access to manage albums.

    Then when I tried to upload an image with my control as an anonymous user I get this error:

    You are not authorized to 'Modify album and manage images' ('Image').

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.UnauthorizedAccessException: You are not authorized to 'Modify album and manage images' ('Image'). 

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically MACHINE\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.


  • I have found and fixed the problem; there was a logic error in my code that I didn't see before I posted this question.