Access verweigert Office 365 / SharePoint online mit globalem Administratorkonto

Ich werde verrückt seit zwei Tagen, um ein Problem zu lösen. Das Problem ist

Ich erstelle eine Konsolen-APP, die über ein globales Administratorkonto mit SharePoint Online kommuniziert (eines, das beim Erstellen eines neuen Abonnements als admin angegeben wurde). Was ich versuche zu erreichen, ist, dass ich jeder Websitesammlung und Unterwebsite von Office 365 eine benutzerdefinierte Aktion mit CSOM hinzufügen möchte. Dieser Code funktioniert einwandfrei, mit Ausnahme der Stammwebsitesammlung, die von Office 365 bei der Anmeldung vorab erstellt wurde (d. Hhttps: //xyz.sharepoint.co)

Für jeden Mandanten für die Stammwebsitesammlung wird der folgende Fehler angezeigt:

{"SchemaVersion": "15.0.0.0", "LibraryVersion": "16.0.3912.1201", "ErrorInfo": {"ErrorMessage": "Zugriff verweigert. Sie haben keine Berechtigung, diese Aktion auszuführen oder auf diese Ressource zuzugreifen." , "ErrorValue": null, "TraceCorrelationId": "2a47fd9c-c07b-1000-cfb7-cdffbe3ab83a", "ErrorCode": - 2147024891, "ErrorTypeName": "System.UnauthorizedAccessException"}, "TraceCorrelationId9c-2a-cd9c:" 1000-cfb7-cdffbe3ab83a "}

Jetzt ist der Benutzer globaler Administrator. Ich habe diesen Benutzer auch erneut als Administrator der Websitesammlung hinzugefügt.

Derselbe Code funktioniert auch für andere Websitesammlungen (Websitesammlung durchsuchen, neu erstellte Websitesammlungen ...).

hier ist ein Code;

        using (ClientContext spcollContext = new ClientContext(web.Url))
        {
            SecureString passWord = new SecureString();
            foreach (char c in strAdminPassword.ToCharArray()) passWord.AppendChar(c);
            SharePointOnlineCredentials creds = new SharePointOnlineCredentials(strAdminUser, passWord);
            spcollContext.Credentials = creds;
            Web currentweb = spcollContext.Web;
            spcollContext.Load(currentweb);
            spcollContext.ExecuteQuery();

       //     authCookie = creds.GetAuthenticationCookie(new Uri(web.Url));

            var existingActions2 = currentweb.UserCustomActions;
            spcollContext.Load(existingActions2);
            spcollContext.ExecuteQuery();
            var actions2 = existingActions2.ToArray();
            foreach (var action in actions2)
            {
                if (action.Description == "CustomScriptCodeForEachsite" &&
                    action.Location == "ScriptLink")
                {
                    action.DeleteObject();
                    spcollContext.ExecuteQuery();
                }
            }

            var newAction2 = existingActions2.Add();
            newAction2.Description = "CustomScriptCodeForEachsite";
            newAction2.Location = "ScriptLink";

            newAction2.ScriptBlock = scriptBlock;
            newAction2.Update();
            spcollContext.Load(currentweb, s => s.UserCustomActions);
            spcollContext.ExecuteQuery(); // GETTING ERROR ON THIS LINE. 
        }

Hinweis: Der obige Fehler bezieht sich auf Fiddler-Spuren.

Antworten auf die Frage(6)

Ihre Antwort auf die Frage