[英]Where to put username & password that remote machine needs to allow files access from desktop application
Check this illustration please http://www.fa6er.com/Image1.png 检查此图请http://www.fa6er.com/Image1.png
Where to put username and password that the desktop application needs to access files in shared directory on a server within local network by IP? 桌面应用程序通过IP访问本地网络中服务器上共享目录中的文件所需的用户名和密码放在哪里?
string var_main_dir = @"\\192.168.1.244\c$\repository";
After this line the application make a connection to the server -BUT- stop and shows debug error message regarding 在此行之后,应用程序与服务器-BUT-停止连接,并显示有关以下内容的调试错误消息:
and invalid username and password 以及无效的用户名和密码
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: username and password 附加信息:用户名和密码
Before connecting to the server you will need to impersonate the login using the username and password you have. 连接到服务器之前,您需要使用您拥有的用户名和密码来模拟登录。 The following stack overflow should help a bit with writing that code: How do you do Impersonation in .NET? 以下堆栈溢出应该对编写该代码有所帮助: 如何在.NET中进行模拟? . 。
A shortened version is: 缩短的版本是:
public Impersonation(string domain, string username, string password)
{
var ok = LogonUser(username, domain, password,
LOGON32_LOGON_NEW_CREDENTIALS, 0, out this._handle);
if (!ok)
{
var errorCode = Marshal.GetLastWin32Error();
throw new ApplicationException(string.Format("Could not impersonate the elevated user. LogonUser returned error code {0}.", errorCode));
}
this._context = WindowsIdentity.Impersonate(this._handle.DangerousGetHandle());
}
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.