Microsoft MVP성태의 닷넷 이야기
.NET Framework: 535. aspnet.config 파일의 설정을 읽는 방법 [링크 복사], [링크+제목 복사],
조회: 14167
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

aspnet.config 파일의 설정을 읽는 방법

aspnet.config 파일의 기본 설정 파일 내용은 다음과 같이 <runtime />, <startup /> 설정만 갖는 것이 일반적입니다.

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <runtime>
        <legacyUnhandledExceptionPolicy enabled="false" />
        <legacyImpersonationPolicy enabled="true"/>
        <alwaysFlowImpersonationPolicy enabled="false"/>
        <SymbolReadingPolicy enabled="1" />
        <shadowCopyVerifyByTimestamp enabled="true"/>
    </runtime>
    <startup useLegacyV2RuntimeActivationPolicy="true" />
</configuration>

그런데 이 값들을 읽어내기 위해 일반적인 web.config 파일을 다루는 방법은 애석하게도 aspnet.config에는 통하지 않습니다. 가령, web.config은 machine.config으로부터 상속되어 내려오는 설정을 다음의 방법으로 읽는 것이 가능하지만,

How to: Access ASP.NET Configuration Settings Programmatically
; https://docs.microsoft.com/en-us/previous-versions/4c2kcht0(v=vs.140)

특이하게도 runtime 섹션에 대해서는 아래의 글에 설명된 것처럼,

ConfigurationManager - reading the “runtime” section
; https://toresenneseth.wordpress.com/2009/04/23/configurationmanager-reading-the-runtime-section/

GetSection 메서드를 이용하면 IgnoreSection 타입의 인스턴스가 반환됩니다.

System.Configuration.Configuration rootWebConfig1 =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

object objSection = rootWebConfig1.GetSection("runtime");
// objSection은 System.Configuration.IgnoreSection 타입의 인스턴스

그래서 아무런 값도 알아낼 수 없습니다. 설령 읽어냈다 해도 그것이 machine.config/web.config 내의 설정일 듯 싶고 aspnet.config의 내용이라는 보장이 없습니다.

어쩔 수 없군요. ^^; 이럴 땐 XmlDocument 타입을 이용해 직접 다음과 같이 읽어오는 것이 현재로써는 최선인 듯 합니다.

string path = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
string aspnetPath = System.IO.Path.Combine(path, "aspnet.config");

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(aspnetPath);
bool canAbortThread = false;

XmlNode policyNode = xmlDoc.SelectSingleNode("/configuration/runtime/legacyUnhandledExceptionPolicy");
if (policyNode != null)
{
    string enabled = policyNode.Attributes.GetNamedItem("enabled").Value;
    canAbortThread = bool.Parse(enabled);
}




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







[최초 등록일: ]
[최종 수정일: 7/17/2021]

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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  72  73  [74]  75  ...
NoWriterDateCnt.TitleFile(s)
11784정성태11/18/201813113Graphics: 32. .NET으로 구현하는 OpenGL (7), (8) - Matrices and Uniform Variables, Model, View & Projection Matrices파일 다운로드1
11783정성태11/18/201811220오류 유형: 504. 윈도우 환경에서 docker가 설치된 컴퓨터 간의 ping IP 주소 풀이 오류
11782정성태11/18/201811001Windows: 152. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선순위 조정 기능 - 두 번째 이야기
11781정성태11/17/201813208개발 환경 구성: 422. SFML.NET 라이브러리 설정 방법 [1]파일 다운로드1
11780정성태11/17/201814670오류 유형: 503. vcpkg install bzip2 빌드 에러 - "Error: Building package bzip2:x86-windows failed with: BUILD_FAILED"
11779정성태11/17/201815039개발 환경 구성: 421. vcpkg 업데이트 [1]
11778정성태11/14/201812797.NET Framework: 803. UWP 앱에서 한 컴퓨터(localhost, 127.0.0.1) 내에서의 소켓 연결
11777정성태11/13/201811855오류 유형: 502. Your project does not reference "..." framework. Add a reference to "..." in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
11776정성태11/13/201811126.NET Framework: 802. Windows에 로그인한 계정이 마이크로소프트의 계정인지, 로컬 계정인지 알아내는 방법
11775정성태11/13/201813643Graphics: 31. .NET으로 구현하는 OpenGL (6) - Texturing파일 다운로드1
11774정성태11/8/201811490Graphics: 30. .NET으로 구현하는 OpenGL (4), (5) - Shader파일 다운로드1
11773정성태11/7/201811232Graphics: 29. .NET으로 구현하는 OpenGL (3) - Index Buffer파일 다운로드1
11772정성태11/6/201813497Graphics: 28. .NET으로 구현하는 OpenGL (2) - VAO, VBO파일 다운로드1
11771정성태11/5/201812751사물인터넷: 56. Audio Jack 커넥터의 IR 적외선 송신기 - 두 번째 이야기 [1]
11770정성태11/5/201819682Graphics: 27. .NET으로 구현하는 OpenGL (1) - OpenGL.Net 라이브러리 [3]파일 다운로드1
11769정성태11/5/201811550오류 유형: 501. 프로젝트 msbuild Publish 후 connectionStrings의 문자열이 $(ReplacableToken_...)로 바뀌는 문제
11768정성태11/2/201811452.NET Framework: 801. SOIL(Simple OpenGL Image Library) - Native DLL 및 .NET DLL 제공
11767정성태11/1/201813006사물인터넷: 55. New NodeMcu v3(ESP8266)의 IR LED (적외선 송신) 제어파일 다운로드1
11766정성태10/31/201814318사물인터넷: 54. 아두이노 환경에서의 JSON 파서(ArduinoJson) 사용법
11765정성태10/26/201811984개발 환경 구성: 420. Visual Studio Code - Arduino Board Manager를 이용한 사용자 정의 보드 선택
11764정성태10/26/201815554개발 환경 구성: 419. MIT 라이선스로 무료 공개된 Detours API 후킹 라이브러리 [2]
11763정성태10/25/201813500사물인터넷: 53. New NodeMcu v3(ESP8266)의 https 통신
11762정성태10/25/201814283사물인터넷: 52. New NodeMCU v3(ESP8266)의 http 통신파일 다운로드1
11761정성태10/25/201813963Graphics: 26. 임의 축을 기반으로 3D 벡터 회전파일 다운로드1
11760정성태10/24/201810456개발 환경 구성: 418. Azure - Runbook 내에서 또 다른 Runbook 스크립트를 실행
11759정성태10/24/201811130개발 환경 구성: 417. Azure - Runbook에서 사용할 수 있는 다양한 메서드를 위한 부가 Module 추가
... 61  62  63  64  65  66  67  68  69  70  71  72  73  [74]  75  ...