我为了读取局域网内另一台机子某一共享文件夹下的文件名称,使用的如下语句
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"/>不过还是出现登录失败的提示,请问有什么解决方法没?

解决方案 »

  1.   

    那就改成windows身份验证嘛。。
    很简单的问题
      

  2.   

    为什么不使用
    <Authentication mode="Windows"/>
      

  3.   

    web.config中使用身份模拟,加入下面结点
    <identity   impersonate="true"   userName="administrator"   password="密码"   />放在</system.web>之前
      

  4.   

    5楼的配置,如果是域用户则输入的userName为:域名\用户名
      

  5.   

    <identity  impersonate="true"  userName="administrator"  password="密码"  /> 这一点,我已经试过了,还是没有用,
    我做的这个必须要用<Authentication mode="Forms"/>
    如果可以用windows验证,我早就用了,如果改成<Authentication mode="Windows"/>
    那我的整个登录验证都要改了!
      

  6.   


    另一台机器上要有userName指定的用户名.
      

  7.   

    要用API访问共享文件夹
    http://www.cnblogs.com/speeding/articles/1156507.html