When you map a network drive, it is mapped for currently logged-on user and
is stored under HKEY_CURRENT_USER registry key. The mapped drive will
therefore be available only for that user. When your ASP.NET application is
run, it does not have access to the mapped drive because in its context it
does not exist.
In your case, you need to worry about security rather than mapping network
drives. When you run your ASP.NET application it is executed in context of
your local ASPNET account (unless you are running your application on domain
controller) which cannot be authenticated agains computers that host shared
folders (unless you try accessing your local shared folders on your
computer). In order to access network folders when no authentication can be
performed (your case) entity which is trying to access a resource is
identified as Guest account, which is probably disabled in your case (and
should remain so).
The best solution to your problem would be impersonating a domain account
(read ASP.NET Impersonation in MSDN) and then giving that account access to
the shared folder.
Another solution, although not recommended and avoided at all costs, would
be enabling guest account on network computer you are trying to access,
which will introduce more problems than it will solve. Stick to
impersonation, it is simple and poses no threats as long as you know how to
secure the access to the registry and your web server.
Hope this helps.
Regards,
--
Vjekoslav Babic, MCSA, MCDBA
Z0gS said:
I got this problem for the web application:
I try to access files on a remote server. string[] dirs = Directory.GetDirectories(@"E:\vehicles");
E drive is a map to a network drive. I get the DirectoryNotFoundException.
How do I solve the problem or the is another way to write the code?