c# - Microsoft.SharePoint.Client.IdcrlException :

我已经通过 Microsoft 365 E5 Developer(没有 Windows 和音频 session ) 注册了 Office 365 Developer Edition。我正在编写代码以连接到开发人员域的 Sharepoint。以下是我的代码:

   public static String GetList( ICredentials credentials)
    {
        var authManager = new OfficeDevPnP.Core.AuthenticationManager();
        using (ClientContext clientContext = 
        authManager.GetWebLoginClientContext("https://xxx.sharepoint.com"))
        {
            clientContext.Credentials = credentials;

            Web web = clientContext.Web;
            clientContext.Load(web,
            webSite => webSite.Title);

            clientContext.ExecuteQuery();
            return web.Title;


        }
    }


    public string callSharepoint()
    {


        const string userName = "Username@domain.onmicrosoft.com";  
        const string password = "xxxx";
        var securePassword = new SecureString();
        foreach (var c in password)
        {
            securePassword.AppendChar(c);
        }
        var credentials = new SharePointOnlineCredentials(userName, securePassword);

        var list = GetList(credentials); 
        return list.ToString();
    }

在运行时,它首先要求输入 Microsoft Office 凭据,然后通过向联系电话发送代码进行验证,然后在验证完成后抛出 Exception on Line clientContext.ExecuteQuery()。异常如下:

Microsoft.SharePoint.Client.IdcrlException:“登录名或密码与 Microsoft 帐户系统中的不匹配。”

我使用的凭据是具有角色 全局管理员 的管理员帐户。我还尝试在该 Active Directory 中添加新用户帐户并尝试使用该凭据,但仍然在同一个地方遇到相同的异常。 我什至尝试删除 Pnp 授权、启用和禁用多因素授权,但没有成功。但是,我可以使用完全相同的凭据在浏览器上成功登录到 Sharepoint 站点。

我认为,我在设置 Office 帐户开发人员订阅时所做的设置很可能存在问题。也许代码没有问题,因为我使用相同的代码登录到我组织的 Sharepoint 并且它工作得很好。也许我需要在开发人员的 Office 帐户中配置其他内容。

如果有人已经对这个问题有所了解,请告诉我。

最佳答案

您已初始化凭据,因此您可以直接使用它,如果存在问题,应该与您的用户帐户或许可证有关。

public static String GetList(ICredentials credentials)
        {
            //var authManager = new OfficeDevPnP.Core.AuthenticationManager();
            //using (ClientContext clientContext =
            //authManager.GetWebLoginClientContext("https://xxx.sharepoint.com/sites/lee"))
            //{

            //}

            using (ClientContext clientContext = new ClientContext("https://xxx.sharepoint.com/sites/lee"))
            {
                clientContext.Credentials = credentials;

                Web web = clientContext.Web;
                clientContext.Load(web,
                webSite => webSite.Title);

                clientContext.ExecuteQuery();
                return web.Title;
            }
        }


        public string callSharepoint()
        {


            const string userName = "user@xxx.onmicrosoft.com";
            const string password = "password";
            var securePassword = new SecureString();
            foreach (var c in password)
            {
                securePassword.AppendChar(c);
            }
            var credentials = new SharePointOnlineCredentials(userName, securePassword);

            var list = GetList(credentials);
            return list.ToString();
        }

关于c# - Microsoft.SharePoint.Client.IdcrlException : 'The sign-in name or password---' Even WITH Pnp Authentication Manager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60934302/

相关文章:

spring-boot - 由于 Content-Security-Policy,Swagger U

encryption - 为什么使用 JSON Web Tokens (JWT) 而不是普通加密

macos - MAC 上 .net 核心应用程序的核心签名 + 强化运行时

python - 与另一个物体接触时改变物体颜色

javascript - 使用 HTML5 播放双音频 MKV/AVI 视频

laravel - 混合内容,此请求已被阻止;内容必须通过 HTTPS 提供,Laravel

python - tf.data 与 tf.keras.preprocessing.image.Im

angular - 如何使用 angular 在 s3 中使用带有多个文件的预签名 url

visual-studio - phpcs — Wordpress 编码标准在 Visual Stu

java - 如何指定嵌套属性的默认值?