Version
- Windows Server 2016
- dotnet-hosting-6.0.2-win
- IIS 10.0
symptoms
- Local tests are normal
- Upload ~<50kb The file of is normal
- Upload ~>60kb The file message of is abnormal 500 (Internal Server Error), And the exception is not caught
Climb a pit
Because no exception is caught by the controller , So my first thought was IIS On the level of .
see IIS journal
No abnormal information is found
open stdoutLog( The key )
Exception information found :
fail: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer[2]
Connection ID "17726168139235852346", Request ID "8000003d-0001-f600-b63f-84710c7967bb": An unhandled exception was thrown by the application.
System.UnauthorizedAccessException: Access to the path 'C:\Windows\TEMP\ASPNETCORE_9df0985f-8e73-4710-a2c6-8c15c60b0835.tmp' is denied.
···
The truth
When trying to cache files on disk , Because of the permission problem of the folder, a System.UnauthorizedAccessException.
solve
to IIS user c:\windows\temp Read / write permission of .
reason
Why? ~50kb Your files can , A little more is not enough ? The reason is found in the description document of the file upload :
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-6.0#file-upload-scenarios
The entire file is read in IFormFile, It is a file C# Representation form , Used to process or save files .
Resources used for file uploading ( disk 、 Memory ) Depends on the number and size of concurrent file uploads . If the app tries to buffer too many Uploads , The site will crash when there is not enough memory or disk space . If the size or frequency of file uploading will consume application resources , Please use streaming .
It will be greater than 64 KB All the individual buffer files are moved from memory to the temporary files on disk .




![[NLP] 3 papers on how Stanford team builds a better chat AI](/img/f1/1c2ff31a728152395618800600df45.jpg)

