I want to make a list of files from a provided path. I need to read all files from a given folder that is on some other server and not on my IIS server.
I mapped the drive on my IIS server to read it, but it's asking me for credentials when the page loads, and I don't want this. I have saved the credential on where the page has been uploaded on IIS and mapped the drive.
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);
}
It works in Visual Studio when I test it but when I deploy it to the server on IIS, then it asks me for a credential, and when I provide the credentials on the browser, nothing happens.
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.
Then I assigned that application pool to my application virtual directory.
Now this code works fine. Before, the identity user on the application pool had no access to the other network path/mapped drive.
So, I provided that user who had access to the path, i.e. in the Security tab of the mapped folder. Now it runs under that user, so it doesn't ask for credentials.