通过我的应用程序,我正在使用WebClient
在线访问文件并进行处理。这是一个这样的例子:
using (var webClient = new WebClient())
{
webClient.Credentials = new NetworkCredential(userName, password, domain);
var bytes = webClient.DownloadData(urlToWorkbook);
Stream stream = new MemoryStream(bytes);
var workbook = new Workbook(stream);
stream.Close();
stream.Dispose();
return workbook;
}
当我通过Visual Studio的调试器开发应用程序和测试时,一切正常。现在我已经部署了应用程序并且它正在通过IIS运行,我在webClient.DownloadData()
调用时收到以下错误:
System.Net.WebException: An exception occurred during a WebClient request. System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
我在本地将我的网站发布到我的机器的IIS上,我得到了同样的例外。我觉得我已经尝试了一百万个代码解决方案。这似乎是VS的Web服务器和IIS之间的区别。我知道在IIS中可以做些什么吗?
答案 0 :(得分:1)
事实证明,这与将文件流打开时间过长有关。我的应用程序从Sharepoint存储中检索文件并循环遍历它们,将文件下载到字节数组中。它似乎不喜欢通过IIS时的方式,所以我重构了一点,以保持流在最短的时间内打开。似乎现在正在工作。