【问题标题】:Connect Intranet(OnPremise) SharePoint Server 2013 from Console C#从控制台 C# 连接 Intranet(OnPremise) SharePoint Server 2013
【发布时间】:2018-06-14 08:02:39
【问题描述】:

我已尝试从控制台实现本地 SharePoint 连接,如下文所述, https://sharepoint.stackexchange.com/questions/205515/first-time-connecting-to-sharepoint-server-2013-from-console/205529?newreg=95ed260c717c4d9fb5fe4856a2daf71a

但事情是,当执行程序时,它会抛出内部异常(代码:500)。无法连接服务器:-(

请检查下面的代码,让我知道我在哪里/做错了什么。

using (var clientContext = new ClientContext("http://customersupport/"))
        {
            try
            {
                Console.WriteLine("connecting on-premise sharepoint....");

                clientContext.Credentials = new NetworkCredential(@"domain\username", "password");

                // Get the SharePoint web  
                Web web = clientContext.Web;

                // Load the Web properties  
                clientContext.Load(web);

                // Execute the query to the server.  
                clientContext.ExecuteQuery();

                Console.WriteLine("Conneciton done successfully");

            }
            catch (Exception exe)
            {
                //throws internal exception
                Console.WriteLine(exe.Message);
            }
        }

以下是完整的错误信息:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
   at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
   at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
   at ConnectSharepoint.SharePointOnPremise.Main(String[] args) in C:\Kishor\ac\2018\Test\ConnectSharepoint\SharePointOnPremise.cs:line 34

提前致谢!

【问题讨论】:

  • 发布 full 异常,包括调用堆栈。您可以通过Exception.ToString() 或简单的Console.WriteLine(exe) 获得它。如果你调用了错误的 URL,你只会得到一个错误。顺便说一句,如果您想使用您当前的凭据连接,您不需要 需要指定用户名/密码。这意味着要么不对.Credentials 属性设置任何内容,要么将其设置为CredentialCache.DefaultCredentials
  • 顺便说一句,而不是随机尝试代码,read the docs。您需要将 SharePoint 站点 URL 传递给构造函数。一个 SharePoint 安装可以有多个 Web 应用程序。这些应用程序又可以有许多独立的站点。
  • @PanagiotisKanavos 我添加了完整的异常消息。
  • 您检查过网址吗?您是否删除凭据,以便可以使用自己的凭据进行连接?你能先连接到那个网站吗?
  • @PanagiotisKanavos 是的,我检查了 CredentialCache.DefaultCredentials ** 和 **CredentialCache.DefaultNetworkCredentials 仍然面临同样的问题。

标签: c# sharepoint sharepoint-2013 intranet


【解决方案1】:

检查以下内容:

1.检查所有应用程序池,并检查“SharePoint Web Services Root”是否停止。

2.检查这些 SharePoint 服务。

3.检查 IIS 管理服务。

【讨论】:

    猜你喜欢
    • 2015-08-08
    • 2015-12-05
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    相关资源
    最近更新 更多