【问题标题】:Sharepoint 2013 Client Object Model Console Application the-remote-server-returned-an-error-403-forbidden-errorSharepoint 2013 客户端对象模型控制台应用程序 the-remote-server-returned-an-error-403-forbidden-error
【发布时间】:2015-04-28 10:56:06
【问题描述】:

我有基于声明的身份验证的 SharePoint 2013 WebApp。此 WebApp 还启用了提供的受信任身份。现在我正在尝试使用以下代码从控制台应用程序连接到网站集之一。

using (var clientContext = new ClientContext(url)) 

{

       var rootweb = clientContext.Web;
       clientContext.Load(rootweb );
       clientContext.ExecuteQuery();
}

每次执行时我都会收到错误: 远程服务器返回-an-error-403-forbidden-error 即使有下面的代码和平

using (ClientContext context = new ClientContext("SiteURL"))

{

    CredentialCache cc = new CredentialCache();
    NetWorkCredential nc = new NetworkCredential("username", "password", "domain"); 

    cc.Add(new Uri("http://localhost"), "Negotiate", nc));

    context.Credentials = cc; 

    Web web = context.Web;
     context.Load(web);

    Log.Debug("Loading web.");
    context.ExecuteQuery();

    Console.WriteLine(web.Title);
}

错误仍然相同。 the-remote-server-returned-an-error-403-forbidden-error.

请建议我应该怎么做才能避免上述错误

【问题讨论】:

    标签: console-application sharepoint-2013 sharepoint-clientobject


    【解决方案1】:

    凭证缓存似乎是您的问题。试试这个例子:

            using (ClientContext context = new ClientContext("https://Your.Site.Url"))
            {
                context.AuthenticationMode = ClientAuthenticationMode.Default;
                context.Credentials = new NetworkCredential("username", "password", "domain");
                Web web = context.Web;
                context.Load(web);
                context.ExecuteQuery();
                Console.WriteLine(web.Title);
                Console.ReadLine();
            }
    

    这对我来说非常有效。

    【讨论】:

    • 我正在尝试同样的方法仍然无法正常工作。 Env 是 SP2016 OnPremise
    猜你喜欢
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    相关资源
    最近更新 更多