Simon
Simon

Reputation: 1463

WCF service: failed to get a directory on server using absolute path

I wrote a WCF service with a function that using absolute path to get directory on server.

it works well in debugging mode of VS2010 which triggers a temporary accessible service.

Then I deployed the service under IIS at this server. However, it told me that it cannot get this directory.

both VS2010 and IIS are in this same server. I am wondering if anything i need to add or modify on this dir path. I just think using absolute path should work...

that simple function is like following:

public void testDir() 
{
            string strPhotoRootPath = @"T:\Data\Image";

            if (!Directory.Exists(strPhotoRootPath))
            {
                ErrorMsg newError = new ErrorMsg();
                newError.errorCode = 1001;
                newError.errorDetails = "Cannot locate the photolog root directory";
                throw new WebFaultException<ErrorMsg>(newError, HttpStatusCode.Forbidden);
            }
            ... //rest codes
}

this T:\ drive is in another server, but is accessible from current machine.

wish I can get some advice here! thanks in advance!

Upvotes: 2

Views: 874

Answers (2)

Aaron Daniels
Aaron Daniels

Reputation: 9664

Use the UNC path instead of a mapped network drive, as the mapped drive is specific to your user account. Also, as KMan pointed out, make sure the application pool identity has access to the UNC path destination.

EDIT based on comment:

Here's a resource on how to set the application pool identity using IIS6 on Win2003. Once you have the domain account correctly configured in IIS, and your application is up and running, then you'll need to make sure the account you used has permissions to the share, as well as permissions on that file system.

Upvotes: 1

Per Kastman
Per Kastman

Reputation: 4504

You must set the access rights on the folder so that the account running your app pool can access t:\

Upvotes: 2

Related Questions