C#未找到网络路径 [英] C# The network path was not found

查看:1365
本文介绍了C#未找到网络路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过网络将文件写入远程目录 - 当我尝试检查目录时,代码失败了:

  if(!Directory.Exists(processingPath))
Directory.CreateDirectory(processingPath);

processingPath的组成类似于

  processingPath = xxxObject.serverPath +processing\\; 

xxxObject.serverPath包含类似这样的内容

  \\machineNetworkName \ sharedFolder \ 

正常工作,但当许多请求正在处理(异步运行)时,它会停止工作并失败到异常:

 系统。 IO.IOException:找不到网络路径。 

你可以帮我解决一下这个问题以及为什么它在网络路径上经过一段时间后失败了?????????????????????????????????????????????????????????????????????????????????????????????同样的错误之前,它是关于身份验证问题。



您必须确保在IIS上正确设置用户,因为它使用默认应用程序池的标识,这可以'访问您的NFS。
您还可以使用IIS虚拟文件夹来设置标识。
(在IIS管理器上,请参阅应用程序池设置 - >身份以及虚拟文件夹设置 - >身份)。



在我的情况下,直接在代码中使用Impersonation会更好用,所以我建议你使用 VladL WrappedImpersonationContext对象:如何在连接到网络共享时提供用户名和密码



要检查的最后一件事,NFS服务器上文件的所有者,如果他们是在root用户下创建,它可能无法正常工作。


Im having trouble with writing files to remote directory via network - exactly, the code fails when I try to check if directory:

if (!Directory.Exists(processingPath))
                Directory.CreateDirectory(processingPath);

processingPath is composed like

processingPath = xxxObject.serverPath + "processing\\";

xxxObject.serverPath contains something like this

\\machineNetworkName\sharedFolder\

Its working properly, but when many requests are processing (running as tasks asynchronously), it stops working and failing into exception:

System.IO.IOException: The network path was not found.

Could you please help me what could be the problem and why it is failing after some time on network path???

Thanks for your solutions

解决方案

I got the same error before, it was about authentication problems.

You have to be sure that you set properly the user on IIS, because it use a Default App Pool's identity which can't access to your NFS. You can also use IIS virtual folders to set the identity. (on IIS manager, see App Pool settings -> Identity and also virtual folders settings -> identity).

In my case, it worked better by using the Impersonation directly in the code, so I recommend you to use the VladL WrappedImpersonationContext Object: How to provide user name and password when connecting to a network share

Last thing to check, the owner of the files on your NFS server, if they were created under the root user, it might not work.

这篇关于C#未找到网络路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆