1

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`enter code here`
    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" />-->
</authorization>

the IIS service is using network account.

Any help is appreciated.

Please note almost all the methods I use work perfectly when debugging on my machine.

It's 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.

honk
  • 9,137
  • 11
  • 75
  • 83
user754975
  • 19
  • 1
  • 4
  • 1
    possible duplicate of [how to grant write permissions to an web api application in IIS?](http://stackoverflow.com/questions/16948452/how-to-grant-write-permissions-to-an-web-api-application-in-iis) – Volkan Paksoy Sep 17 '15 at 18:46
  • hmm... Jim answers Jim's question?.. btw, your title threw me a bit.. for, **local client** in the context of **site** doesn't make me think **server**.. . – Brett Caswell Sep 17 '15 at 18:53
  • and, as soon as I read **seems to not work, I assumed** I went down to these comments for possible clarification.. .but since it isn't here, I'll ask it.. Are you supressing errors/exceptions? have you tried handling Application_OnError in your Global Application file? Have you looked at any logs? – Brett Caswell Sep 17 '15 at 19:03

1 Answers1

2

I've actually answered this same question before...

https://stackoverflow.com/a/16948507/1246574

Here's the steps copied from that post.

Grant permissions for your folder to the application pool. You'd browse to the folder in Windows and edit permissions, and add IIS APPPOOL\appPoolNameHere as a user, then give it whatever permissions you need.

Step by Step Instructions...

-Open Windows Explorer

-Browse to your folder

-Right click the folder and go to Properties

-On the Security tab click Edit

-Click Add

-Under Locations, make sure it is pointing at your local machine, not a domain

-For the object name, enter below but replace MyAppPool with the name of your application pool...

IIS APPPOOL\MyAppPool

-Set the permissions to Full, or just add Write, or whatever you need.

Community
  • 1
  • 1
Jim
  • 6,753
  • 12
  • 44
  • 72
  • Thank you for your answer, however the idea is not to ask people to do this for folders they will use to upload files. i was hoping to use anprotected folders like windows\temp, etc.. – user754975 Sep 17 '15 at 19:47
  • Thank you for your answer, however the idea is not to ask people to do this for folders they will use to upload files. i was hoping to use anprotected folders like windows\temp, etc.. – user754975 Sep 17 '15 at 19:48