0

我正在尝试编写一个控制台应用程序来连接到我们的一个共享点应用程序站点。我正在运行一个基本示例来确保连接性。该程序一直失败并出现以下错误:远程服务器返回错误:(500)内部服务器错误。

状态:System.Net.WebExceptionStatus.ProtocolError

我无权访问 IIS 服务器来检查日志。我的代码如下:

        string siteUrl = "http://spsiteurl/";


        ClientContext clientContext = new ClientContext(siteUrl);
        clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
        clientContext.Credentials = new NetworkCredential("...", "...", "...");

        Web oWebsite = clientContext.Web;

        clientContext.Load(oWebsite,
            w => w.Title);

        clientContext.ExecuteQuery();

        Console.WriteLine(oWebsite.Title);

关于我可能出错的任何方向?

4

1 回答 1

1

试试下面的代码

    ClientContext context = new ClientContext("https://test.com/");
    System.Net.ServicePointManager.ServerCertificateValidationCallback =
        ((sender, certificate, chain, sslPolicyErrors) => true);

    string strUserName = @"abc";
    string strPassword = "pwd";
    var credentials = new NetworkCredential(strUserName, strPassword);
    Web web = context.Web;
    context.Load(web, w => w.Title);
    context.Credentials = credentials;
    context.ExecuteQuery();


    // Now, the web's properties are available and we could display 
    // web properties, such as title. 
    System.Console.WriteLine("Web Title");
    System.Console.WriteLine(web.Title);

它会在控制台中正常工作

于 2014-12-11T12:49:30.917 回答