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.