I have a .net website that resides on a webserver running IIS 6.0 on win2k3 server. This includes a virtual directory that points via a UNC name to a file server. The "connect as" is set to use a service account in our AD domain that has access to the web application as well as write and modify to the file server folder. I am currently using aliasing with the service account and have set the appropriate permissions on the Miscrosoft.net temp files folder on the web server. I am unable to create a write directory or save a file. Any information will be appreciated.
views:
328answers:
2First, "Connect as" passwords will not be cached forever in memory (reboot) and you may need to seek alternative to this connectivity method for that reason unfortunately.
Secondly, does the ASP.NET worker account "IUSR_IIS Machine Name" have access to the destination directory you are writing on? I am assuming no, because it will not be a known user on the remote server. This means that the "Everyone" special user/object will have to be given access (in your particular scenario).
An alternative would be to connect using a user known to both hosts.
I have this working now. In order for this to work properly you need: 1. A service account with a non-expiring password in your domain that is accessible to the web server and file server 2. You create the appropriate virtual folder with the "connect as" set to the service account with the appropriate password 3. You need to give Write permissions to the service account to the .net Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files directory on the server 4. The service account has to be given read/write/modify access to the file folder 5. The "save as" must be the full UNC name to the file server. Do not use server.map path, but the full name to the folder such as: \myserver\sharename\directory\ + filename. I am storing mine in the web.config as a key/value pair.
That sums it up.
Code snippet:
try { if (uploadDoc.FileName != "") {
if (!Directory.Exists(MyFilePath))
Directory.CreateDirectory(ServerFilePath);
if (!File.Exists(Server.MapPath(ServerFileName)))
{
uploadDoc.PostedFile.SaveAs(SaveLocation);
}