파일 액세스 권한 문제...

안녕하세요, .net core 로 된 api 서버를 iis 에서 실행되도록 해놨습니다.
그리고 api 요청을 했을 때 아래와 같은 에러 메시지가 나옵니다.,.(윈도우 이벤트 뷰어 로그)
아래 에러 내용은 파일을 저장하려고 할 때 권한이 없어서 그렇다고 알고 있는데요…
아래 소스 처럼 파일을 저장 할 때 CmsUser 라는 계정 권한을 가지고와서 모든 허용을 하도록 했는데요… 이렇게 해도 파일 저장이 안됩니다. 그리고 iis 가 실행되는 폴더도 CmsUser 로 모든 권한을 다 줬습니다…

이런 경우 어디를 수정해야할까요

using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
var fileInfo = new FileInfo(filePath);
var security = fileInfo.GetAccessControl();
var user = new NTAccount(“CmsUser”);
security.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow));
fileInfo.SetAccessControl(security);

                using (StreamWriter writer = new StreamWriter(fileStream, ansi))
                {
                    writer.Write(text);
                }
            }

===============에러 메세지 ==================
Exception: **
System.UnauthorizedAccessException: Access to the path ‘C:\inetpub\Restio\cms\Rest_Str\20230418_9922215819_등록해지요청_전문.txt’ is denied.
** at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)

** at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode)** ** at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode)**
** at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)**
** at System.IO.FileSt**
===============================

2개의 좋아요

위 링크에 있는 내용으로 IIS 게스트 계정 추가하고 권한을 줘서 해결 했습니다…

2개의 좋아요

IIS 게스트 계정이 아닌, 내가 추가한 계정으로 폴더 권한이 체크 되도록 할 수 있을까요…

2개의 좋아요

위 링크에 있는 내용에서 폴더- 보안에서 개체 이름을 IIS APPPOOL\MyAppPool 로 등록해주면 되네요! IIS APPPOOL\MyAppPool 여기에서 MyAppPool 은 IIS 에서 만든 애플리케이션 풀 이름 입니다.

3개의 좋아요