Click here to Skip to main content
15,311,151 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Good Morning

I am doing a project where the user is allowed to upload/download a file to sql stream.

This works perfectly when testing it locally but when i uploads it and have an IIS, it seems to not work. I assumed it is a permission issue.

I am unable to solve it.

I even tried to use unprojected folders as shown below (with no luck)

string tempPath = System.IO.Path.GetTempPath();
string tempPath2 = System.Environment.GetEnvironmentVariable("TEMP");
string tempPath3 = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
var fullpath = Path.Combine(tempPath2, "MeDoc.Doc");

I even tried using authentications as show below (also no luck)


DirectoryInfo di = new DirectoryInfo(fullpath);
DirectorySecurity acl = di.GetAccessControl();
AuthorizationRuleCollection rules = acl.GetAccessRules(true, true, typeof(NTAccount));
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(currentUser);

DirectorySecurity fsecurity = Directory.GetAccessControl("C:\\Temp\\Docs\\");
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
FileSystemAccessRule writerule = new FileSystemAccessRule(sid, FileSystemRights.Write, AccessControlType.Allow);

fsecurity.AddAccessRule(writerule);
// Set the ACL back to the file
Directory.SetAccessControl("C:\\Windows\\Temp\\", fsecurity);


if (!string.IsNullOrEmpty("C:\\Temp\\Docs\\") && Directory.Exists("C:\\Temp\\Docs\\"))
{
// Get your file's ACL
DirectorySecurity fsecurity3 = Directory.GetAccessControl("C:\\Temp\\Docs\\");

// Add the new rule to the ACL
fsecurity3.AddAccessRule(writerule);

// Set the ACL back to the file
Directory.SetAccessControl("C:\\Temp\\Docs\\", fsecurity);
}

even in web.config

<authorization>
<allow users="?">
<!--<anonymousauthentication enabled="true">-->


the iis service is using network account.


any help is appreciate it.

please note almost all the methods i use work perfectly when debugging on my machine.

its a different story when it is on iis on a web server running network account.

in IIS it is using a pool that uses Network service (yes i also tried local system with no luck)
as for the site permission i allow read and write.

if anyone can help or even better yet have a quick sample project. i would greatly appreciate it.

thanks

again

Jim
Posted

Your code is running on the server. It is accessing folders on the server, not on the client.

It might appear to work when you debug locally, but that's just because the server and client are the same machine in that specific instance.

Code running on the server cannot access files on the client. If you need the client to upload a file, then you have to give them a <input type="file"> to select the file, and save the uploaded file somewhere on the server.

File Upload with ASP.NET[^]
   
Comments
Member 10449741 17-Sep-15 15:59pm
   
I need a common folder where people need to put documents to upload as well as a folder for download.
right now the its access denied to access any local folder on the client machine
Sergey Alexandrovich Kryukov 17-Sep-15 17:07pm
   
Okay, keep needing it... :-) This is absurd...
My advice is to learn what Web does, just in basics principles; right now, you have no clue.
—SA
Dev O'Connor 17-Sep-15 17:12pm
   
If your machine are networked, try using a network share directory and use impresonation within ASP that has sufficient permissions to that directory then have the client web page reference the shared folder?

For obvious security concerns, you cannot access Far end resources from the server, otherwise all hackers would do it :)
Richard Deeming 18-Sep-15 9:23am
   
And if you read my answer, you'll see that I've already told you what the problem is:
Code running on the server CANNOT access files on the client.

The users will need to select the relevant files and upload them to the server. When they want a local copy, your code will need to transmit the file to the client, and they will have to choose where to save it.

And no, there is no way to force the client to upload a file from a particular path, and there is no way to force the client to save a file in a particular path or with a particular name.
Sergey Alexandrovich Kryukov 17-Sep-15 17:05pm
   
Ha-ha, a 5.
—SA
I'll bet the error tells you exactly what the problem is.

However, you said it is using the network account. That account won't have permissions to create files on the drive. Either grant the account the proper permissions or change the account to one that does have sufficient permissions.
   
Comments
Member 10449741 18-Sep-15 13:38pm
   
The idea is to use an unprotected temp folder in windows
hence this : string tempPath = System.IO.Path.GetTempPath();
string tempPath2 = System.Environment.GetEnvironmentVariable("TEMP");
string tempPath3 = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);


otherwise there must be a way to impersinate or use ntuser authentication
ZurdoDev 18-Sep-15 13:39pm
   
Are you asking a question?
Member 10449741 18-Sep-15 16:20pm
   
yes
i guess you cant help
thanks anyways
ZurdoDev 18-Sep-15 16:30pm
   
I'm not sure what you mean. Of course we can help. If you are asking a question, then please be clear about it. I didn't understand what the point of your last message was.
Member 10449741 21-Sep-15 14:26pm
   
is there a way to use the current authenticated users domain account to access their own folders?
Member 10449741 21-Sep-15 15:55pm
   
i was looking at solutions like this but arent working for me
http://stackoverflow.com/questions/5298905/add-everyone-privilege-to-folder-using-c-net
ZurdoDev 21-Sep-15 19:58pm
   
If you set your site to use NT Authentication then they could, if it's under IIS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900