Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 9개 있습니다.)
오류 유형: 51. Vista(UAC) + 웹 프로젝트 디버깅: System.UnauthorizedAccessException
; https://www.sysnet.pe.kr/2/0/563

오류 유형: 211. ASP.NET 응용 프로그램을 IIS Express에서 디버깅할 때 "Requested registry access is not allowed" 오류 발생
; https://www.sysnet.pe.kr/2/0/1593

오류 유형: 234. IIS Express에서 COM+ 사용 시 SecurityException - "Requested registry access is not allowed" 발생
; https://www.sysnet.pe.kr/2/0/1726

디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
; https://www.sysnet.pe.kr/2/0/13239

디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
; https://www.sysnet.pe.kr/2/0/13240

디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
; https://www.sysnet.pe.kr/2/0/13241

디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
; https://www.sysnet.pe.kr/2/0/13242

오류 유형: 895. ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'
; https://www.sysnet.pe.kr/2/0/13559

오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
; https://www.sysnet.pe.kr/2/0/13562




ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'

예전에도 언급했던 오류인데,

IIS Express에서 COM+ 사용 시 SecurityException - "Requested registry access is not allowed" 발생
; https://www.sysnet.pe.kr/2/0/1726

ASP.NET 응용 프로그램을 IIS Express에서 디버깅할 때 "Requested registry access is not allowed" 오류 발생
; https://www.sysnet.pe.kr/2/0/1593

이번엔 소스코드를 들여다보며 정리했기 때문에 기록을 남깁니다.




IIS에서 .NET Framework 4.8용의 ASP.NET 웹 프로젝트를 "System.Security.SecurityException" 예외에 대해 "thrown" 옵션을 넣고 실행하면 이런 오류가 발생할 수 있습니다. (개인적으로 가능한 모든 오류를 thrown으로 둬서 모르고 지나가는 예외를 최대한 없게 하자는 원칙을 가지고 있습니다.)

System.Security.SecurityException
  HResult=0x8013150A
  Message=Requested registry access is not allowed.
  Source=mscorlib
  StackTrace:
   at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) in f:\dd\ndp\clr\src\BCL\system\throwhelper.cs:line 107

  This exception was originally thrown at this call stack:
    System.ThrowHelper.ThrowSecurityException(System.ExceptionResource) in throwhelper.cs

이때의 호출 스택에 따라,

>    mscorlib.dll!System.ThrowHelper.ThrowSecurityException(System.ExceptionResource resource) Line 70   C#  Symbols loaded.
    mscorlib.dll!Microsoft.Win32.RegistryKey.OpenSubKey(string name, bool writable) Line 827    C#  Symbols loaded.
    System.Web.dll!System.Web.Util.Misc.GetAspNetRegValue(string subKey, string valueName = null, object defaultValue = null) Line 179  C#  Symbols loaded.
    System.Web.dll!System.Web.Compilation.CompilationMutex.CompilationMutex(string name = "CL9dcc5588", string comment = "CompilationLock for /") Line 23   C#  Symbols loaded.
    System.Web.dll!System.Web.Compilation.CompilationLock.CompilationLock() Line 13 C#  Symbols loaded.
    [Native to Managed Transition]      Annotated Frame
    [Managed to Native Transition]      Annotated Frame
    ...[생략]...

GetAspNetRegValue 메서드를 보면 아래와 같이 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0" 하위 키를 열려고 시도하는데,

[RegistryPermission(SecurityAction.LinkDemand, Unrestricted = true)]
[RegistryPermission(SecurityAction.Assert, Unrestricted = true)]
internal static object GetAspNetRegValue(string subKey, string valueName, object defaultValue)
{
    try
    {
        using RegistryKey registryKey = OpenAspNetRegKey(subKey);
        if (registryKey == null)
        {
            return defaultValue;
        }
        return registryKey.GetValue(valueName, defaultValue);
    }
    catch
    {
        return defaultValue;
    }
}

internal static RegistryKey OpenAspNetRegKey(string subKey)
{
    string text = VersionInfo.SystemWebVersion; // .NET Framework 4.8의 경우: text == "4.0.30319.0"
    if (!string.IsNullOrEmpty(text))
    {
        int num = text.LastIndexOf('.');
        if (num > -1)
        {
            text = text.Substring(0, num + 1) + "0";
        }
    }
    string text2 = "Software\\Microsoft\\ASP.NET\\" + text;
    if (subKey != null)
    {
        text2 = text2 + "\\" + subKey; // text2 == "SOFTWARE\Microsoft\ASP.NET\4.0.30319.0" + subKey
    }
    return Registry.LocalMachine.OpenSubKey(text2);
}

이때 전달된 subKey 값을 찾아보면,

internal CompilationMutex(string name, string comment)
{
    string text = (string)Misc.GetAspNetRegValue("CompilationMutexName", null, null);
    if (text != null)
    {
        _name = _name + "Global\\" + name + "-" + text;
    }
    else
    {
        _name = _name + "Local\\" + name;
    }
    _comment = comment;
    _mutexHandle = new HandleRef(this, UnsafeNativeMethods.InstrumentedMutexCreate(_name));
    if (_mutexHandle.Handle == IntPtr.Zero)
    {
        throw new InvalidOperationException(SR.GetString("CompilationMutex_Create"));
    }

}

결국 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\CompilationMutexName" 경로임을 알 수 있습니다. 따라서, 이번에도 역시 해당 레지스트리 키에 대해 Read 권한을 주는 것으로 해결할 수 있습니다.





[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 2/19/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...
NoWriterDateCnt.TitleFile(s)
12183정성태3/11/202010012오류 유형: 601. Warning: DsGetDcName returned information for \\[...], when we were trying to reach [...].
12182정성태3/11/202011226.NET Framework: 901. C# Windows Forms - Vista/7 이후의 Progress Bar 업데이트가 느린 문제파일 다운로드1
12181정성태3/11/202012004기타: 76. 재현 가능한 최소한의 예제 프로젝트란? - 두 번째 예제파일 다운로드1
12180정성태3/10/20208627오류 유형: 600. "Docker Desktop for Windows" - EXPOSE 포트가 LISTENING 되지 않는 문제
12179정성태3/10/202020063개발 환경 구성: 481. docker - PostgreSQL 컨테이너 실행
12178정성태3/10/202011580개발 환경 구성: 480. Linux 운영체제의 docker를 위한 tcp 바인딩 추가 [1]
12177정성태3/9/202011169개발 환경 구성: 479. docker - MySQL 컨테이너 실행
12176정성태3/9/202010599개발 환경 구성: 478. 파일의 (sha256 등의) 해시 값(checksum) 확인하는 방법
12175정성태3/8/202010707개발 환경 구성: 477. "Docker Desktop for Windows"의 "Linux Container" 모드를 위한 tcp 바인딩 추가
12174정성태3/7/202010252개발 환경 구성: 476. DockerDesktopVM의 파일 시스템 접근 [3]
12173정성태3/7/202011237개발 환경 구성: 475. docker - SQL Server 2019 컨테이너 실행 [1]
12172정성태3/7/202016127개발 환경 구성: 474. docker - container에서 root 권한 명령어 실행(sudo)
12171정성태3/6/202011116VS.NET IDE: 143. Visual Studio - ASP.NET Core Web Application의 "Enable Docker Support" 옵션으로 달라지는 점 [1]
12170정성태3/6/20209714오류 유형: 599. "Docker Desktop is switching..." 메시지와 DockerDesktopVM CPU 소비 현상
12169정성태3/5/202011737개발 환경 구성: 473. Windows nanoserver에 대한 docker pull의 태그 사용 [1]
12168정성태3/5/202012434개발 환경 구성: 472. 윈도우 환경에서의 dockerd.exe("Docker Engine" 서비스)가 Linux의 것과 다른 점
12167정성태3/5/202011675개발 환경 구성: 471. C# - 닷넷 응용 프로그램에서 DB2 Express-C 데이터베이스 사용 (3) - ibmcom/db2express-c 컨테이너 사용
12166정성태3/4/202011299개발 환경 구성: 470. Windows Server 컨테이너 - DockerMsftProvider 모듈을 이용한 docker 설치
12165정성태3/2/202010972.NET Framework: 900. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 네 번째 이야기(Monitor.Enter 후킹)파일 다운로드1
12164정성태2/29/202011798오류 유형: 598. Surface Pro 6 - Windows Hello Face Software Device가 인식이 안 되는 문제
12163정성태2/27/202010263.NET Framework: 899. 익명 함수를 가리키는 delegate 필드에 대한 직렬화 문제
12162정성태2/26/202013072디버깅 기술: 166. C#에서 만든 COM 객체를 C/C++로 P/Invoke Interop 시 메모리 누수(Memory Leak) 발생 [6]파일 다운로드2
12161정성태2/26/20209704오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202010376개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/20208548오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202010386디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
... 46  47  48  49  50  51  52  53  54  55  56  57  [58]  59  60  ...