Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WebException响应没有';我不能返回完整的答复_C#_.net_Asp.net Web Api_Webclient_Windows Authentication - Fatal编程技术网

C# WebException响应没有';我不能返回完整的答复

C# WebException响应没有';我不能返回完整的答复,c#,.net,asp.net-web-api,webclient,windows-authentication,C#,.net,Asp.net Web Api,Webclient,Windows Authentication,我正在使用Web API服务(Windows Authenticated)中的WebClient对公司目录(Windows Authenticated)进行HTTP调用,以获取用户的配置文件。请看下面 public string DownloadPage(string ntid) { var result = ""; try { using (var client = new WebClient() {UseDef

我正在使用Web API服务(Windows Authenticated)中的WebClient对公司目录(Windows Authenticated)进行HTTP调用,以获取用户的配置文件。请看下面

public string DownloadPage(string ntid)
    {
        var result = "";

        try
        {
            using (var client = new WebClient() {UseDefaultCredentials = true})
            {
                using (var stream = client.OpenRead($"{url}{urlParameter}{ntid}"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        result = reader.ReadToEnd();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            log.Error(ex); 
        }

        log.Info(result);
        return result;
    }
该代码在本地和我们的测试环境中运行良好,但在我将其部署到Produciton环境时返回了“500 internal server error”。我根据来自的解决方案解决了500错误。请参阅下面的代码。然而,我发现只有部分html被返回。我是否需要从代码或IIS中设置任何类似正文长度或最大返回大小的内容

 public string DownloadPage(string ntid)
    {
        var result = "";

        try
        {
            using (var client = new WebClient() {UseDefaultCredentials = true})
            {
                using (var stream = client.OpenRead($"{url}{urlParameter}{ntid}"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        result = reader.ReadToEnd();
                    }
                }
            }
        }
        catch (WebException webex)
        {
            //https://stackoverflow.com/questions/4098945/500-internal-server-error-at-getresponse
            var errResp = webex.Response;
            using (var stream = errResp.GetResponseStream())
            {
                using (var reader = new StreamReader(stream))
                {
                    result = reader.ReadToEnd();
                }
            }
        }
        catch (Exception ex)
        {
            log.Error(ex); 
        }

        log.Info(result);
        return result;
    }

我认为您可以访问active directory,这就是代码在本地IIS上工作的原因,但在IIS上,应用程序池是从ApplicationPoolIdentity运行的,而ApplicationPoolIdentity没有访问权限


转到应用程序池并将身份更改为您的帐户。这里有一张图片供您参考:

您能给我们看一下显示完整内容长度的响应标题吗?返回了多少内容?HTML响应有多大?您能用捕获流量来查看真正的响应吗?谢谢!应用池标识是问题所在。