I am trying to access the Root site list using the sub site client context. But when I try to execute the clientcontext
it gives Access Denied error.
I tried to create new clientcontext
by passing the accessToken
as well but no success. (Referred: This)
Below is the code:
clientContext.Load(clientContext.Site);
clientContext.ExecuteQuery();
string siteUrl = clientContext.Site.Url;
Uri webUri = new Uri(siteUrl);
string realm = TokenHelper.GetRealmFromTargetUrl(webUri);
string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken;
using (var cc = TokenHelper.GetClientContextWithAccessToken(siteUrl, accessToken))
{
cc.Load(cc.Web);
cc.ExecuteQuery();
}
Here, clientContext
is the context of Sub-Site and cc is the context of Root site.
How can I access the cc using clientContext
?