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" :
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