spilliton spilliton - 15 days ago 5
ASP.NET (C#) Question

Asp.net FileUploader doesn't work when using UNC file path

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.

Answer

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.

Comments