Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a website hosted on IIS where i want to list network drives name.I am able to get network drive names available on my computer when I run my website from visual studio but its returning blank while running from IIS.My IIS version is 10.

What I have tried:

var drives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Network);
foreach (DriveInfo d in drives)
{
Response.Write(d.Name + "
");
}
Posted
Updated 10-Feb-20 5:08am

You need to change the account your code runs under in IIS to one that has the access you need, the default account can't access the network. Just remember it opens up security risks as any exploits found in your code are now run under that elevated account and could potentially be far more serious.

What you have to change exactly and how depends on your version of IIS and how your site is set up so google for more info if this doesn't help

Configure the Anonymous Authentication Identity (IIS 7)[^]
 
Share this answer
 
v2
The chances are that it works in development because the server and the client are the same machine: so when your C# code runs, it looks at your dev machine and returns the network drive info.
When you move to production and run it under IIS, the server is no longer running on the same computer as the client, and can only ever get access to networked drives connected to the server - it cannot access any information from the client at all.
So teh network drives it reports are those connected to the server, not the client - which is almost certainly none, just to be on the safe side. It would be unusual to connect network drives on a web server.
 
Share this answer
 
Comments
Richard Deeming 1-Feb-18 15:51pm    
Network drives aren't connected to a computer; they're connected to a session.

IIS is running the code under a different user account, in a different session. So even if it's on the same computer, it won't see the mapped drives from the OP's session.
Per Microsoft documentation mapped drives are not a viable solution.
Sure you can work your way around it and eventually make it work... But its a bad idea because it will cause performance degreation as every call has to be authenticated twice, once by the OS and once by IIS.

Use a UNC path instead.

https://support.microsoft.com/en-us/help/257174/using-mapped-drives-with-iis[^]

https://support.microsoft.com/en-us/help/207671/how-to-access-network-files-from-iis-applications[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900