通过应用程序,我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)
编辑:另一个奇怪的事情是,当我将此代码放在控制器的Index动作(这是一个MVC)应用程序上时,它成功执行了DownloadData()调用。只有当调用被嵌入到我的应用程序中(需要它)时,它才会失败。
我将站点本地发布到了计算机的IIS,并且遇到了同样的异常。我觉得我已经尝试了上百万种代码解决方案。看来VS的网络服务器和IIS之间是有区别的。对我可以在IIS中做什么有任何想法?
事实证明,这与文件流打开时间过长有关。我的应用程序从Sharepoint存储中检索文件并循环遍历,将文件下载到字节数组中。似乎不喜欢通过IIS时的处理方式,因此我进行了一些重构,以使流在最短的时间内保持打开状态。似乎现在可以工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句