简体   繁体   English

如何在asp.net网站/页面上的映射驱动器中读取文件

[英]How to read files in a mapped drive on asp.net website/page

I want to make a list of files from a provided path. 我想从提供的路径中列出文件列表。 actually I need to read all files from a given folder that is on some other server and not on my iis server. 实际上,我需要从其他服务器而非iis服务器上的给定文件夹中读取所有文件。

I mapped the drive on my iis server to read it but its asking me for credentials when page loads. 我将驱动器映射到iis服务器上以进行读取,但是在页面加载时它要求我提供凭据。 I dont want this. 我不想要这个。 I have saved the credential on where the page has been uploaded on iis and mapped the drive. 我已将凭据保存在iis上载页面的位置并映射了驱动器。

     string xrayPath = @"\\172.18.0.23\or\CARM\" + xrayPath;
    List<FileInformation> directories = new List<FileInformation>();
    List<FileInformation> lstFiles = new List<FileInformation>();
    List<FileInformation> lstAllFiles = new List<FileInformation>();

      System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(xrayPath);



        int fileId = 0;
        PoplateFiles(ref lstFiles, ref directories, dir, 0, ref fileId);

        foreach (var file in directories)
        {
            file.isDirectory = true;
            lstAllFiles.Add(file);
        }

        foreach (var file in lstFiles)
        {
            file.isDirectory = false;
            lstAllFiles.Add(file);
        }

////////// //////////

Please help me out, it works in visual studio when I test it but when I deploy it on iis on server, then it's asking me for credential and I am providing the credentials on browser, even then nothing happens. 请帮帮我,当我对其进行测试时,它可以在Visual Studio中工作,但是当我在服务器上的iis上部署它时,它会要求我提供凭据,并且我在浏览器上提供了凭据,即使这样也没有任何反应。 Please guide me. 请指导我。

I think I have resolved the issue myself. 我想我已经解决了这个问题。 On the server where I mapped the drive, I created an application pool and selected the user that has access to the mapped drive in the identity field of application pool and set the Load User Profile to true. 在映射驱动器的服务器上,我创建了一个应用程序池,并在应用程序池的标识字段中选择了有权访问映射驱动器的用户,并将“加载用户配置文件”设置为true。 then I assigned that application pool to my application virtual directory. 然后将该应用程序池分配给我的应用程序虚拟目录。 Now, this code worked fine. 现在,此代码可以正常工作。 Before that actually the identity user on application pool had no access to the other network path/mapped drive. 在此之前,应用程序池上的身份用户实际上无法访问其他网络路径/映射的驱动器。 So, I provided that user who had access to the path ie. 因此,我提供了有权访问该路径的用户,即。 in the security tab of the mapped folder. 在已映射文件夹的安全性选项卡中。 Now it runs under that user, so it doesnt ask for credentials. 现在,它在该用户下运行,因此它不要求提供凭据。 I hope it works.... 我希望它能起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM