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.
Access to the path is deniedAccess to the path 'C:\' is denied 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
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- Unable to cast object of type System.InvalidCastException: Unable to cast object of type 'X' to type 'Y'
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026