views:

1415

answers:

2

Let me start by saying, I'm no expert in windows file permissions, so maybe there is something very basic I am missing here.

I have a Asp.net FileUploader control. I have a folder on the same machine as the Asp.net application I would like files to be uploaded to.

I want to be able to tell the FileUploader to put the files in

\\thisMachineName\UploadFolder\

but I always get an exception stating that access to that path is denied.

If I change the directory to be

c:\UploadFolder\

it works fine. Also, I can put the above UNC into windows explorer and it does in fact map to the directory.

Any ideas or thoughts?

--Update Note: This is a Windows 2000 server box, and the folder has "Everyone" granted all of the possible allow permissions.

+1  A: 

YOU can put files in that directory, but what about the user that the ASP.NET process is running as? on Windows Server 2003 (and presumably 2008, but I'm not sure), ASP.NET runs under the NETWORK SERVICE account, which has almost no rights whatsoever, especially across the network. You'll have to use impersonation on the ASP.NET app or setup a share with Everyone access. For this type of scenario, I usually just setup a share with Everyone access and firewall protect it so only the web server(s) have access.

Chris
Thanks for the response Chris. I added an update note to my post since I forgot to include that this is a 2k server box, and the permissions I have on the UploadFolder.I just tried giving "NETWORK SERVICE" full permissions and I still get the access denied error.
spilliton
+2  A: 

The one thing I always see people doing is that they fail to set permissions on the share. To set up a shared folder, you have to do the following:

1) Determine the account under which you will be connecting to the share
2) Grant this account access rights on the file system
3) Grant this account access rights to the network file share

No. 1, in this case, usually means checking your configuration or simply using process explorer to determine under what account ASP.NET is running. Plenty of info on google about how to do this.

No. 2 is the obvious one. You log on the machine where the physical drive exists, browse to the folder in explorer, right click on it and hit the security tab. We've done this a bazillion times.

No. 3 is where people mess up. Yes, the worker account now has rights to the local file system, but not to CONNECT to the local file system over the network. From the Security tab skip back to the network sharing tab and look for a Permissions button. You'll use this to grant the worker account rights to connect to the share.

The second issue I've seen is when people attempt to grant access rights on machine A to an account that only exists on machine B. This won't work, generally. Both machine A and machine B have to belong to a common domain which both A and B trust to authenticate users. Most often businesses running Windows use ActiveDomain to control access rights on the network.

In order to have the ASP.NET worker process on machine B access the share on machine A, the worker process must be running under an account that is authenticated on the network, not just the local machine. Most often you'll have to create a specific account on the network and give that account rights to both machines, and then use that account to run the ASP.NET worker process for your website.

If you're scratching your head, you've got some learning to do. This stuff isn't easy. I strongly suggest reading the following:

http://msdn.microsoft.com/en-us/library/ms978378.aspx

Its relatively clear and contains everything you need to know.

Will
Thanks a lot Will!I had no idea that when you use a UNC (even though in my case it is referring to the local computer) that it went through this network share security stuff in addition to the folder's normal permissions.I gave ASPNET user read/write access to the share and all is gravy now.
spilliton