0

I have a pdf file on a windows server running IIS7 that I use as a template to create a printable/offline version of my web form. I access it in an APS.NET application using an .ashx handler. Initially it worked fine, until I moved to Production, then it gave me Access to the path 'D:\inetpub\site\My PDF.pdf' is denied.

First I tried changing the App Pool identity, in case it was a permissions issue. I also added full control permissions for that identity. Doing this broke it in the lower environment as well. When the app pool was switched back to the original(ApplicationPoolIdentity), it still didn't work.

I'm finding the file via HttpContext.Current.Server.MapPath, which works as expected. Then I'm using FileStream existingFileStream = new FileStream(fileNameExisting, FileMode.Open) to open the file for editing via iTextSharp. The file has permissions for 'Network Service'.

Any help would be appreciated. Let me know if you need more information.

I apologize if this is the wrong site for this question. If it is, please let me know and I will move it to the proper one.

EDIT:

Below is the the permissions via icacls of the file in the production environment. MYDOMAIN, CustomAppIdentity, WEBSERVER, and LabManagers have names changed for security.

MYDOMAIN\CustomAppIdentity:(F)
NT AUTHORITY\NETWORK SERVICE:(F)
NT AUTHORITY\Authenticated Users:(I)(RX)
NT AUTHORITY\SYSTEM:(I)(F)
WEBSERVER\LabManagers:(I)(M)
BUILTIN\Administrators:(I)(F)
BUILTIN\Users:(I)(RX)
NT SERVICE\TrustedInstaller:(I)(F)

EDIT: Event Information

Event code: 4011 
Event message: An unhandled access exception has occurred. 
Event time: 7/1/2015 11:07:56 AM 
Event time (UTC): 7/1/2015 6:07:56 PM 
Event ID: 9c4a06e4465744da8d76e27f3d954c30 
Event sequence: 48 
Event occurrence: 3 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/8/ROOT/MyProject-1-130802388056279071 
    Trust level: Full 
    Application Virtual Path: /MyProject 
    Application Path: D:\inetpub\parent-site\MyProject\ 
    Machine name: MYSERVER 

Process information: 
    Process ID: 4236 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\MyProject 

Request information: 
    Request URL: http://parentsite.url/MyProject/PdfHandler.ashx 
    Request path: /MyProject/PdfHandler.ashx 
    User host address: 159.1.15.73 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: IIS APPPOOL\MyProject

Custom event details: 
Chloe
  • 101
  • 4
  • What are the permissions on that file? Can you add the result of `icacls.exe "D:\inetpub\site\My PDF.pdf"` – Peter Hahndorf Jul 01 '15 at 02:32
  • @PeterHahndorf I've added it at the end. – Chloe Jul 01 '15 at 15:33
  • Looks like there are enough permissions there. If you have a quiet time on the server, I would run Process Monitor to check for `Access Denied`. – Peter Hahndorf Jul 01 '15 at 16:20
  • You can verify if this is a permissions issue by (**temporarily!**) giving the `Everyone` group access to the file. – Joel Coel Jul 01 '15 at 18:22
  • @JoelCoel I have `Everyone` full control. It still says `System.UnauthorizedAccessException: Access to the path 'E:\inetpub... etc...' is denied.`. – Chloe Jul 01 '15 at 18:45
  • Then it's not (only) a permissions problem. Access can be denied for reasons other than permissions. Is the file opened somewhere? – Joel Coel Jul 01 '15 at 18:46
  • @JoelCoel I tried deleting and recreating the app-pool, site, and directory. It did not change the problem. The problem also occurs on multiple servers. – Chloe Jul 01 '15 at 19:04
  • It sounds like something is opening the file exclusively, and then not closing it. Is it possible that only the first request for the file works? – Joel Coel Jul 01 '15 at 19:17
  • @JoelCoel I thought of that. When I deleted and re-created the site, tried immediately afterward to no avail. This is a test environment, so no one else could have touched the file. In the code I'm using a `using` statement, so the file stream should get closed regardless. – Chloe Jul 01 '15 at 21:05

1 Answers1

0

The handler PDFHandler.ashx had the wrong language, vb rather than c#, which was causing the exception. This was not a server problem, it was simply throwing a misleading error. So far, this has fixed the problem.

Chloe
  • 101
  • 4