tags:

views:

28

answers:

2

I have a virtual directory setup in IIS6. This maps to a shared network drive.

I can correctly map the path using

string mappedPath = HttpContext.Current.Server.MapPath(path);

I then create a DirectoryInfo object as I want to find some files in the directory.

DirectoryInfo updateDirectory = new DirectoryInfo(mappedPath);

But then updateDirectory.Exists is false?? I can take the string from the mappedPath and copy into Start->Run to get to the path so I know it exists. I am authenticating to the webservice using integrated windows authentication and have permissions to the necessary folders.

Is there something obvious I'm missing in the code? Or is this purely set-up and configuration of IIS etc.?

+3  A: 

You need to check whether your service working process account has access rights to that folder. AFAIK windows authentication does not bring impersonation to the working process so it can be different with your windows acct. Alternatively (just to prove account issues) you can run the app pool using your account to see if problem will go away.

Alex Krupnov
+1  A: 

According to this link:

http://bytes.com/topic/asp-net/answers/471616-server-mappath-virtual-directories

Server.MapPath doesn't give expected output when used against virtual directories.

If it is server permissions and you are using Windows Authentication, make sure you have this in your config:

<identity impersonate="true" /> 

DirectoryInfo returns false on error conditions: if the folder isn't there; you don't have permissions; or it's a disconnected network folder.

Sounds like permissions of your ASP.NET worker process to me - the impersonation will solve this.

Adam
<identity impersonate="true" /> did the trick nicely, thank you.
Peter Kelly
Cool, so I can remember something from doing ASP.NET! Windows Auth is applied to the current user principal, but you need to promote the Worker Process manually.
Adam