如何进行身份验证以访问共享文件夹 [英] How to do authentication to access shared folder

查看:631
本文介绍了如何进行身份验证以访问共享文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ac#code将图像复制到特定文件夹,就像下面这样简单:

I have a c# code to copy image to specific folder just as simple as below:

string fileName = "image.jpg";
string source = "c:\photos\" + fileName;
string destination = "\\172.16.242.41\photos\" + fileName;
File.Copy(source, destination);



问题是:目的地是局域网中服务器计算机上的共享文件夹,需要验证(用户名密码)。我不希望它为我的用户。 Windows 2008在我的服务器上运行。



有没有办法在代码中进行身份验证以访问服务器的共享文件夹?


Problem is: destination is shared folder on Server computer in the LAN and it requires authentication (username, password). I do not want it for my users. "Windows 2008" runs on my server.

Is there any way to do authentication to access shared folders of Server in code?

推荐答案

你可以使用这个小C#模仿用户的类别 [ ^ ]

和复制文件如下

you can use this small C# Class for impersonating a User[^]
and copy file as below
using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   // code that executes under the new context.
   File.Copy(source, destination);
}





附加参考:

使用凭据连接到UNC路径 [ ^ ]


请告诉我DomainName的一个示例。

对于我的情况,域名是\\172.16.242.41\photos \,对吗?
Pls show me a sample of DomainName.
DomainName is "\\172.16.242.41\photos\" for my case, right?


这篇关于如何进行身份验证以访问共享文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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