System.UnauthorizedAccessException: Access to the path 'x' is denied
The process’s identity can’t read/write that file or folder — IIS app pool identity, container user, read-only attribute, or a directory passed where a file was expected.
Seen on:
.NET
Meaning
Apps running under IIS AppPool\Name, a Windows service account, or non-root container users often lack rights to write logs/uploads. Read-only files and trying to open a directory as a file give the same exception.
Common causes
- App pool/service/container user lacks permission
- File marked read-only
- Path is a directory, not a file
- Writing under Program Files / protected folders
⚡ Quick fix
- Grant the app identity rights on the folder
- Write to an app-specific data folder
- Check the path points to a file
Detailed fix by platform
Windows
icacls C:\inetpub\myapp\App_Data /grant "IIS AppPool\MyAppPool:(OI)(CI)M"
How to diagnose
- Identity — Which user runs the app?
- Path — File or directory?
- Attributes — Read-only?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in .NET
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026