繁体   English   中英

连接到 shared.network 资源并不总是有效

[英]Connecting to shared network resources doesn't always work

我正在使用本教程中的代码远程访问文件C# NetworkConnection 用于文件共享或其他远程通信

我可以连接到远程目录并访问只是.jpg图像的文件。

这是访问图像的代码:

[HttpGet]
public ActionResult GetPhoto(string cpuNr, Int64 imageNameNr)
{
    string source = @"ipadress\photos";
    string imgPath = Path.Combine(path where the image is from the cpuNr and imageNameNr build toghether);

    FileContentResult result = null;

    using(var share = new NetworkConnection(source, new NetworkCredentials())
    {
        byte[] fileContent = System.IO.File.ReadAllBytes(imgPath);
        result = File(fileContent, "image/jpeg");
    }

    return result;
}

这在大多数情况下都可以正常工作。 但有时我会得到一个错误:

网络错误:System.ComponentModel.Win32Exception (0x80004005):
连接到远程共享时出错。

无法访问源。 这并不意味着不能始终访问特定图像,因为有时可以访问,有时不能访问。

有什么办法解决这个错误,任何修复,因为我找不到任何可以帮助我进一步找到这个问题的原因或解决方案的东西。

编辑同一个文件,来自同一个路径,同一个用户,有时可以正常访问,但有时不能。

这是一个 Windows 限制。 使用异步时,多个请求会在等待上一个响应时发送。 而 windows 会阻止那些没有的请求。 将我的 function 调用从异步更改为在 JS 文件中同步,这很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM