Last post Apr 09, 2018 08:31 AM by PatriceSc
Apr 09, 2018 03:03 AM|sheilaanderson|LINK
.NET 4, c#
The app creates a file using:
FileStream fileStream = new FileStream(documentPath, System.IO.FileMode.Create)
And fetches the file using:
MemoryStream mem = new MemoryStream();
byte byteInfo = File.ReadAllBytes(documentName);
This has been working for years, except for recently some of the files cannot be opened.
The problem files are owned by "ASP.NET v4.0", but not all ASP.NET v4.0 owned files have this problem. I checked permissions, and for the ones that had the problem, there was a permissions entry for user "ASP.NET v4.0" for which the only permissions checked
were Special Permissions, both the "allow" and "deny" boxes were checked. The file also has user "NULL SID" listed with Special Permissions "deny" only, and also has an Everyone user listed with Special Permission "allow".
Since I was not the ASP.NET v4.0 user I could not remove these permissions to see if that would have an effect, but by changing file ownership to "Administrators" the problem for this file was solved.
Don't know if is relevant, but when I look at the files from a Cygwin bash shell, "ls -l" shows permissions 070, and both user and group ownership are "ASP.NET v4.0". But again there are many files like this that don't have the problem.
We seem to be able to reproduce this rather consistently, i.e. use the app to create a .docx file, then find out that the file cannot be opened with the app until I "fix" it by either copying the file back and forth (which implicitly changes it's permission)
or explicitly changing the ownership.
We are running:
So I am trying to figure out what's going on, is it a folder permissions setting somewhere, or one of the IIS settings, or a Windows user setting? Assuming that the iis worker is running as user ASP.NET v4.0, then when it creates a file it is setting some
permissions that don't allow it to reopen the file. I can always open the file from Windows Explorer, just not from the web app until the file is "fixed".
Any help would be much appreciated!
Apr 09, 2018 08:31 AM|PatriceSc|LINK
With "cannot be opened" I first thought you were creating invalid docx files. IMO it is best to always tell explicitely which error message you have to avoid a posisble misunderstanding.
The account under which your app runs should be IIS AppPool\<pool name>. See
https://docs.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities#securing-resources and check this account is allowed to access the file. Usually it is a read permission. You'll need read/write on the folder in which you are
creating those files...