The Microsoft document File upload scenarios says "Any single buffered file exceeding 64 KB is moved from memory to a temp file on disk. Temporary files for larger requests are written to the location named in the ASPNETCORE_TEMP environment variable. If ASPNETCORE_TEMP is not defined, the files are written to the current user's temporary folder."
The above mean that the IIS worker process shall have the proper access right to the ASPNETCORE_TEMP or current user's temporary folder if file is larger than 64KB.
I guess that by default the IIS worker process does not have the access right to such folder.
Therefore, first try increasing the value of MemoryBufferThreshold (64KB by default) such like below and uploading the file of more than 64KB and less than 128KB.
services.Configure<FormOptions>(options =>
{
options.MemoryBufferThreshold = 131072; // 128 KB
});
If the result is successful, try giving the proper access right to the IIS worker process. Below is the suggestion given by Copilot (not validated):
What Happens with Files >64 KB
When a file exceeds the MemoryBufferThreshold of 64 KB:
- ASP.NET Core buffers it to disk.
- It writes to the folder specified by the
ASPNETCORE_TEMP environment variable.
- If
ASPNETCORE_TEMP is not set, it defaults to the current user's temp folder — which, under IIS, typically means the temp folder of the application pool identity.
Why This Can Cause Upload Failures
If the app pool identity (e.g., IIS AppPool\MyAppPool) does not have write access to the temp folder being used, buffering fails. This can result in:
- Silent upload failures
- HTTP 500 errors
- Unexpected behavior with no clear error message
How to Fix It
You have two options:
Option 1: Set ASPNETCORE_TEMP to a Custom Writable Folder
(1) Create a folder like C:\MyAppTemp
(2) Grant write permissions to the app pool identity:
- Use
icacls or folder properties → Security tab
- Add
IIS AppPool\YourAppPoolName with Modify rights
(3) Set the environment variable:
[System.Environment]::SetEnvironmentVariable("ASPNETCORE_TEMP", "C:\MyAppTemp", "Machine")
(4) Restart IIS
Option 2: Grant Access to Default Temp Folder
- Identify the default temp folder (e.g.,
C:\Windows\Temp)
- Grant write access to the app pool identity. Be cautious: this folder is shared by many processes, so a dedicated folder is safer
How to Confirm
You can log the temp path used by ASP.NET Core:
var tempPath = Path.GetTempPath();
_logger.LogInformation($"Temp path: {tempPath}");