# System.UnauthorizedAccessException: Access to the path 'x' is denied

**Code:** `Access to the path is denied` · **Category:** .NET · **Seen on:** .NET

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.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/dotnet/unauthorizedaccessexception-access-to-path-denied)
