我为了读取局域网内另一台机子某一共享文件夹下的文件名称,使用的如下语句
DirectoryInfo myinfo = new DirectoryInfo(@"\\192.168.1.12\工作文档");
FileInfo[] myfileinfo = myinfo.GetFiles();
for (int i = 0; i < myfileinfo.Length; i++)
{
ListBox1.Items.Add(myfileinfo[i].Name);
}
目的是将文件名称加到ListBox1中,如果Webconfig中<Authentication mode="Windows"/>可以直接访问,但我的webConfig中验证方式为<Authentication mode="Forms">所以为了能正确的访问,在上面的代码前加上string server = "\\\\192.168.1.12\\root\\cimv2";
string UserName = "administrator";
string Pass = "****";
ConnectionOptions options = new ConnectionOptions();
options.Username = UserName; //格式:机器名或所在域名
options.Password = Pass; //对应的密码
ManagementScope scope = new ManagementScope(server, options);
scope.Connect();并且webconfig中加入了<identity impersonate="true"/>不过还是出现登录失败的提示,请问有什么解决方法没?
DirectoryInfo myinfo = new DirectoryInfo(@"\\192.168.1.12\工作文档");
FileInfo[] myfileinfo = myinfo.GetFiles();
for (int i = 0; i < myfileinfo.Length; i++)
{
ListBox1.Items.Add(myfileinfo[i].Name);
}
目的是将文件名称加到ListBox1中,如果Webconfig中<Authentication mode="Windows"/>可以直接访问,但我的webConfig中验证方式为<Authentication mode="Forms">所以为了能正确的访问,在上面的代码前加上string server = "\\\\192.168.1.12\\root\\cimv2";
string UserName = "administrator";
string Pass = "****";
ConnectionOptions options = new ConnectionOptions();
options.Username = UserName; //格式:机器名或所在域名
options.Password = Pass; //对应的密码
ManagementScope scope = new ManagementScope(server, options);
scope.Connect();并且webconfig中加入了<identity impersonate="true"/>不过还是出现登录失败的提示,请问有什么解决方法没?
很简单的问题
<Authentication mode="Windows"/>
<identity impersonate="true" userName="administrator" password="密码" />放在</system.web>之前
我做的这个必须要用<Authentication mode="Forms"/>
如果可以用windows验证,我早就用了,如果改成<Authentication mode="Windows"/>
那我的整个登录验证都要改了!
另一台机器上要有userName指定的用户名.
http://www.cnblogs.com/speeding/articles/1156507.html