C# 将XML文件从一台服务器读取到同一网络上的另一台服务器

C# 将XML文件从一台服务器读取到同一网络上的另一台服务器,c#,xml,impersonation,file-copying,C#,Xml,Impersonation,File Copying,我在一台IP为12.3.4.56的服务器上托管了我的应用程序,我的数据存储位于同一网络中另一台IP为12.3.4.57的服务器上 我想将XML文件从数据存储服务器读取到应用服务器。 当我在运行提示中触发“\\12.3.4.57\ABC\DEF\”时,它会在两台服务器上打开正确的文件夹。我还为每个人提供了对文件夹的读/写共享访问权限 当我尝试使用下面的代码从我的应用服务器读取文件时,它会抛出一个错误 string XMLFilePath = "\\12.3.4.57\ABC\DEF\dir.xml

我在一台IP为12.3.4.56的服务器上托管了我的应用程序,我的数据存储位于同一网络中另一台IP为12.3.4.57的服务器上

我想将XML文件从数据存储服务器读取到应用服务器。 当我在运行提示中触发“\\12.3.4.57\ABC\DEF\”时,它会在两台服务器上打开正确的文件夹。我还为每个人提供了对文件夹的读/写共享访问权限

当我尝试使用下面的代码从我的应用服务器读取文件时,它会抛出一个错误

string XMLFilePath = "\\12.3.4.57\ABC\DEF\dir.xml";
XmlDocument DirDoc = new XmlDocument();
DirDoc.Load(XMLFilePath);
错误:用户名或密码不正确

当我尝试使用下面的代码将文件从数据存储服务器复制到应用服务器时,也发生了相同的错误

string sourceFile = "\\12.3.4.57\ABD\DEF\Test123 (26).pdf";
string Folder = HttpContext.Current.Server.MapPath("~/SavedPDFs");
string destPDFFile = string.Concat(Folder, "Test123 (26).pdf");
System.IO.File.Copy(sourceFile, destPDFFile, true);

我相信您忘记了避开导致“许可”问题的反斜杠

您的代码应该如下所示

string XMLFilePath = @"\\12.3.4.57\ABC\DEF\dir.xml"; // note the leading @ sign
XmlDocument DirDoc = new XmlDocument();
DirDoc.Load(XMLFilePath);


string sourceFile = @"\\12.3.4.57\ABD\DEF\Test123 (26).pdf";  // note the leading @ sign
string Folder = HttpContext.Current.Server.MapPath("~/SavedPDFs");
string destPDFFile = string.Concat(Folder, "Test123 (26).pdf"); // I assume that the Folder variable will have the frontslash at the end
System.IO.File.Copy(sourceFile, destPDFFile, true);

这听起来像是一个文件安全问题,而不是编程问题。谢谢你在这里指导我。我应该在这里做些什么来解决它?是否不属于模拟问题?运行这些代码的用户必须是目标计算机的用户。听起来您需要正确配置网络和文件共享权限。您可以删除所有代码,只留下文件共享信息,然后在IIS中询问它这是一个Web应用程序吗?哪个用户帐户正在运行网站?(应用程序池)