1

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?

abhi
  • 1,644
  • 1
  • 18
  • 33
tarun713
  • 1,977
  • 2
  • 15
  • 29
  • Have you tried using Server.MapPath? Directory.Exists(Server.MapPath(@"E:\subdirectory")); – Kramb Mar 02 '16 at 21:00
  • 1
    `I think I have a unique problem.` very naive .. :) – Eser Mar 02 '16 at 21:04
  • @Kramb, thanks, but that throws an exception: 'E:/subdirectory' is a physical path, but a virtual path was expected. – tarun713 Mar 02 '16 at 21:07
  • 1
    @Eser To clarify, all the threads I found were around shares not working because folks were not running IIS under the proper user context. I was running under the proper user context from what I could tell. – tarun713 Mar 02 '16 at 21:07
  • @tarun713 see (and use) https://msdn.microsoft.com/en-us/library/windows/desktop/aa385413(v=vs.85).aspx – Eser Mar 02 '16 at 21:10

1 Answers1

1

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.

Scott Chamberlain
  • 116,967
  • 28
  • 260
  • 389
  • That does work, but shouldn't the mapped drive persist for any session since I marked it to persist? – tarun713 Mar 02 '16 at 21:04
  • No, persist just makes it re-map if you end your session then start a new one with the same user. – Scott Chamberlain Mar 02 '16 at 21:04
  • 1
    If you really want, [here is a hack](http://stackoverflow.com/a/4763324/80274) that lets you do `net use E: \\servername\sharename /persistent:yes` inside session 0 so it will be persisisted for that session. Do at your own risk, i really do reccomend you do not use it and instead just use the network path. – Scott Chamberlain Mar 02 '16 at 21:05