Access to the path is denied 🟪 .NET

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

  1. Grant the app identity rights on the folder
  2. Write to an app-specific data folder
  3. Check the path points to a file

Detailed fix by platform

Windows

  1. icacls C:\inetpub\myapp\App_Data /grant "IIS AppPool\MyAppPool:(OI)(CI)M"

How to diagnose

  1. Identity — Which user runs the app?
  2. Path — File or directory?
  3. 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:

🧠 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.