简体   繁体   中英

Directory.Exists for network paths in ASP.NET

I am trying to get:

Directory.Exists(@"E:\subdirectory")

to return "true" when running from ASP.NET when E: is a persistent mapped network drive. I used the following command to map it from a command line running under the context of my user, which returns successfully and does not prompt for credentials:

net use E: \\servername\sharename /persistent:yes

At this point I'm running entirely locally.

When I run the Directory.Exists line from a console app or linqpad, it returns true. When I run this from an ASP.NET application running under IIS ( not IIS express), it returns false.

I have changed my application pool to use the same user account I run as locally. I've verified this has taken effect by:

  • Checking my windows process list and ensuring w3wp.exe is running under my user account.
  • Attaching my ASP.NET application to w3wp.exe and setting a breakpoint, then checking Environment.UserName and Environment.UserDomainName to validate I'm running in the context of my user account.

However, my ASP.NET application still returns false when checking for the network share.

Why is this?

Mapped network drives are tied to the user session. IIS is running in session 0, your mapped drive is running in most likely session 1.

I don't know of any way to make network drives show up for other sessions when you create them for your session, I think you will need to not use E:\\ and instead use \\\\servername\\sharename for the path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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