IIS Virtual Directory map to network drive (with drive letter) but fail to create file

Gavin picture Gavin · Dec 21, 2010 · Viewed 33k times · Source

I am using C#/ASP.NET, IIS6 on Windows Server 2003.

  1. Map the data server shared folder to the WebServer with driver letter V:\

  2. On the WebServer, IIS created a virtual directory and pointed to 'local location' with V:\ . Since there is no 'Connect As', not sure which USER will be used

  3. In my WebMethod, I want to create file on the shared folder with FileStream.Write().

    I got IO Exception on the action, any hint?

P.S. I have added ASPNET/NETWORK SERVICE on the data server shared folder.

thanks! Gavin

Answer

Kev picture Kev · Dec 21, 2010

Mapped network drives are specific to the user account that created them:

Using Mapped Drives with IIS - MS KB257174

The preferred method of accessing content for the Web server that exists on a remote computer is to use shares that follow the universal naming convention (UNC).

It's very likely that NETWORK SERVICE (or if you're running ASP.NET under impersonation, the site anonymous account) hasn't got this mapping.

To change the location where the virtual directory points to, browse to your site in IIS manager, right click on the virtual directory and select properties. You can then select "A share located on another computer":

alt text