0

I've made a SharePoint Provider Hosted App. Into the App Web Project, displayed through a Web Part in my SharePoint Page, I have a web page named Default.aspx.

On this page I have a button, on which I attached an event listener on click.

Here is the relevant C# code-behind of this page :

public void btnSave_Click(object sender, EventArgs e)
{
       //string userName = this.Context.User.Identity.Name;
       bool isAdmin = false;
       SPUser user = SPContext.Current.Web.CurrentUser;
       try
       {
            if (user.Groups["Administrators_Sharepoint"] != null)
            {
                isAdmin = true;
            }
            else
            {
                isAdmin = false;
            }
        }
        catch
        {
            notificationArea.InnerHtml = "identification error";
        }
        //SPGroup adminGroup = site.Groups["Administrators_Sharepoint"];
        //bool isAdmin = site.IsCurrentUserMemberOfGroup(7);

        if (isAdmin)
        {
            notificationArea.InnerHtml = "OK !";
        }
}

Issue : When I try to read a value of the Groups list of user, the page returned is the one saying "Let us know why you need to access this site" :

message displayed when I the above method is called

If I remove the user.Groups[xxxxx],or user.Groups.xxx calls from my page, it will correctly execute the code and not display this message.

Note : the user context I get is the good one, and the account is farm and site administrator for test purposes. So I don't understand why I should have an access denial on this.

EDIT : In the SharePoint logs, when checking the query sent I got a System.UnauthorizedAccessException error at Microsoft.SharePoint.SPWeb.InitWeb() .... at ActivityBoxWeb.Pages.Default.btnSave_Click(Object sender, EventArgs e)

I've added to my App read and write rights for site collection, for test purposes. Not solved yet.

EDIT 2 : With the system account of Sharepoint, it works. He is in the same group of my administrator user. They have the exact same rights.

EDIT 3 : It's totally insane. Others members of the security group doesn't have this "Let us know why you need to access to this site" request page. I am the only one, with the same rights, to land on this access denied page.

Thanks for guiding me, can't figure out how to trace the origin of this issue

  • This SharePoint is driving me crazy. Still stuck, I tried to go by getting the CurrentContext or opening the Web from an URL, then querying for my current user, but still not working. – Alex Jul 17 '15 at 8:18
  • I was on another task, but recently I tried another way and I don't get this message anymore. I create NetworkCredential item and provide administrator account, then I load the user from the clientcontext, and i execute query. But i still can't get the group list to which he belong (void group list) – Alex Aug 3 '15 at 7:37
  • To sum up, when I use a SPUser object to get a group, I get the unauthorized message, but when it's a User object, group list void but no error message at all. – Alex Aug 3 '15 at 8:31
1

I have also faced similar kind of issue in one of my event receiver,

I changed "Who can view the membership of the group" to everyone. This resolved my issue. enter image description here

  • thanks for the reply, sorry it's not the issue here : this option was already checked for me. I just tried "Who can edit the membership of the group" to "Group Members" too, but doesn't worked. – Alex Jul 16 '15 at 9:07
0

Hi app installed in SharePoint can't access all the details from the hosted web. in project you have to specify the permission in app-manifest.xml that what content you want to access from host web. This will get the permission while installing the app and only tenant administrator and access the complete details about users information and some other thing. so may be user group also need permission so check bellow screen shot here you can see the how to get the access to the host web contents.

Check the permissions tab in the AppManifest.xml windows

enter image description here

  • thanks for the answer, I forgot to notice I already tried to modify those. I put the write or manage access to List, Web Site Collection and Users profiles. I can confirm my issue is not caused by a lack of permission in AppManifest. – Alex Jul 17 '15 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.