+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Album Permissions

Album Permissions

2 posts, 0 answered
  1. Thomas Weidman
    Thomas Weidman avatar
    38 posts
    Registered:
    19 Apr 2004
    15 Apr 2011
    Link to this post
    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()
        .Album(this.ImageAlbum)
        .Get();
     
    LibrariesManager manager = LibrariesManager.GetManager();
    manager.BreakPermiossionsInheritance(album);
                         
    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);
        album.Permissions.Add(permissionForEveryone);
    }
    permissionForEveryone.GrantActions(true, SecurityConstants.Sets.Image.View);
    manager.SaveChanges();

    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.


    Thanks,

    -Thomas
  2. Thomas Weidman
    Thomas Weidman avatar
    38 posts
    Registered:
    19 Apr 2004
    17 Apr 2011
    Link to this post
    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.
2 posts, 0 answered