Read file on a remote server

送分小仙女□ 提交于 2019-12-08 08:56:28

问题


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.

How can I pass my credentials??

if I go start/run and put this path, I need to provide credentials lets say Admin and password 123.

Im using Asp.net, c# 3.5

Any Ideas


回答1:


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




回答2:


Your application will need to run as a user that has access to the UNC path, or else impersonate a user with such permissions, for the file load operation.




回答3:


You'd need to be pre-authenticated on the share before you can access the files. It isn't something you can do just by passing a UNC path.

You might consider executing a net use command via the shell programatically. That's the only way I can find to do this.



来源:https://stackoverflow.com/questions/2417878/read-file-on-a-remote-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!