0

I've got a script that checks if a file exists. The path is a network share that exists on the server..

I.e. the directory is D:\Mainfolder\Subfolder\file.txt the network share is \Server\Subfolder\file.txt

The file exists, however from my asp.net site, it says that it doesn't.. I assume that this is a permissions issue since it works if the file is in a different folder.

I've added a bunch of accounts to the permissions of both the share and the folder, but nothing is working..

Is there a way to display which user the File.Exists is being executed as?

Thanks

Matt
  • 4,140
  • 9
  • 40
  • 64
  • You can turn on auditing on your file server to figure out what account is performing the file access. – Gabe Sep 06 '11 at 03:29

4 Answers4

2

The user that is accessing the files is the user configured on the application pool of the ASP.NET site or virtual directory. By default, this user will not have access to many local folders/files, let a lone a network share. You have two options:

  1. Change the user configured for the application pool to a user that has access to not only the local files necessary to run the site, but also has access to the network share.

  2. Configure impersonation in the Web.config. See this other SO question here which has a snippet of configuration from Web.config for impersonation.

Some links:

Community
  • 1
  • 1
Sumo
  • 4,066
  • 23
  • 40
0

Starting with Vista a Windows Service is not allowed to access "Desktop things" - one of these being a mounted drive letter aka network share...

You could mess around with the permissions etc. but even if you get it to work this is not supported...

What is the exact goal ? Perhaps there is some other way...

Yahia
  • 69,653
  • 9
  • 115
  • 144
0

It's probably going to be the user that your application pool is running under. You can see the list of application pools in IIS manager.

However, you can also use Process Monitor to see what users are trying to access the files on your server (including attempts that fail due to insufficient permissions). You can find it at http://technet.microsoft.com/en-us/sysinternals/bb896645. You'll probably need to run this on the remote server where the file actually exists.

Another thing to consider is that while the D:\ drive might be mapped as a network drive when you log in interactively with your account, it probably doesn't exist when the website user is 'logged in'. You'd be better off telling the website to use the UNC path (\server\subfolder...) rather than the D:\ path.

CodeThug
  • 3,054
  • 1
  • 21
  • 17
0

As others have mentioned, your application is probably running under the Application Pool identity. Unless you've changed it explicitly, this account will not show up in your list of accounts to configure.

Getting that sorted out isn't going to help you, though, if you are attempting to access a resource though a mapped drive, as the mapped drive exists only within the scope of the logged-in user.

Think of it this way: you and a colleague share a machine, and you map drive D:\ to \serverA\Shared\Matt, your colleague isn't going to log in and have drive D:\ mapped to your share. She can freely map drive D:\ to \serverX\Secret\Resources.

Start by making sure that you are using a UNC path, then work through the web of permissions issues.

Jay
  • 56,361
  • 10
  • 99
  • 123