I have deployed an asp.net mvc web application on IIS 8 server inside an virtual machine (Windows server 2012 R2). An azure file storage is mapped as network drive in this virtual machine Windows server 2012 R2. Now my asp.net mvc web application needs to read the files and folders of this mapped drive by C# System.IO code. By default IIS is not allowed to access mapped drives.
That's why the web application is throwing System.IO exception
"Could not find the specified path Z:\"
. I also tried to pass "\\\\{storage-name}.file.core.windows.net\\{fileshare-name}
but still no success.
Can some one guide me with correct configurations and settings which I should do inside IIS and web application?
In the IIS Manager , select the Application Pool under which your Web Site is running. Click "Advanced Settings". There will be an entry for Identity (it is under the Process Model section). Click it, provide credentials for your account that has permission to access the share.
As a rule of thumb Windows services can't access mapped drives and you have to use UNC paths instead.
Select Map Network Drive from the Tools menu. Select the drive that you want to use to connect to your server. Type the path name to your server. For example, \\MYSERVER where MYSERVER is the name of your server.
Finally, I succeeded to access the mapped network drive through IIS Server. I performed following steps.
That's it. Now you can simply write standard C# IO code to access the directory and files of mapped drive. Here is a sample example.
var allDirs = Directory.GetDirectories("\\\\<storageaccountname>.file.core.windows.net\\<storagefileshare>");
ViewBag.Items = allDirs;
Make sure that you access the files and folders by UNC path format only, just like I have done in above code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With