读取远程服务器上的文件 [英] Read file on a remote server
问题描述
我在远程服务器上有一个文件,我想读取该文件. 可以说文件位置是:
I have a file on a remote server and I want to read this file. lets say the files location is:
string filePath = @"\\192.168.101.15\c$\program files\xxx\test.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
此代码肯定会引发错误: 登录失败:用户名未知或密码错误.
This code is for sure throwing an error: Logon failure: unknown user name or bad password.
我如何通过我的凭据?
如果我开始/运行并放置此路径,则需要提供凭据,例如Admin和密码123.
if I go start/run and put this path, I need to provide credentials lets say Admin and password 123.
我使用Asp.net,C#3.5
Im using Asp.net, c# 3.5
任何想法
推荐答案
您必须使用模拟功能,即与具有访问共享文件夹权限的用户而不是asp.net用户一起执行代码:
You have to use impersonation, ie execute your code with a user who has acces to the shared folder instead of asp.net user :
http://msdn.microsoft.com /en-us/library/aa292118%28VS.71%29.aspx
您有两种方法: -带代码 -带有配置
You have two way : -with code -with configuration
这篇关于读取远程服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!