Server.MapPath() returning a path that does not exist when used with DirectoryInfo
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
开发者_StackOverflow社区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.?
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.
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.
精彩评论