Microsoft MVP성태의 닷넷 이야기
.NET Framework: 535. aspnet.config 파일의 설정을 읽는 방법 [링크 복사], [링크+제목 복사],
조회: 14172
글쓴 사람
정성태 (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)
11934정성태6/7/201913020VC++: 133. typedef struct와 타입 전방 선언으로 인한 C2371 오류파일 다운로드1
11933정성태6/7/201913072VC++: 132. enum 정의를 C++11의 enum class로 바꿀 때 유의할 사항파일 다운로드1
11932정성태6/7/201911621오류 유형: 544. C++ - fatal error C1017: invalid integer constant expression파일 다운로드1
11931정성태6/6/201911724개발 환경 구성: 441. C# - CairoSharp/GtkSharp 사용을 위한 프로젝트 구성 방법
11930정성태6/5/201912252.NET Framework: 842. .NET Reflection을 대체할 System.Reflection.Metadata 소개 [1]
11929정성태6/5/201912059.NET Framework: 841. Windows Forms/C# - 클립보드에 RTF 텍스트를 복사 및 확인하는 방법 [1]
11928정성태6/5/201910686오류 유형: 543. PowerShell 확장 설치 시 "Catalog file '[...].cat' is not found in the contents of the module" 오류 발생
11927정성태6/5/201911679스크립트: 15. PowerShell ISE의 스크립트를 복사 후 PPT/Word에 붙여 넣으면 한글이 깨지는 문제 [1]
11926정성태6/4/201913149오류 유형: 542. Visual Studio - pointer to incomplete class type is not allowed
11925정성태6/4/201911960VC++: 131. Visual C++ - uuid 확장 속성과 __uuidof 확장 연산자파일 다운로드1
11924정성태5/30/201913705Math: 57. C# - 해석학적 방법을 이용한 최소 자승법 [1]파일 다운로드1
11923정성태5/30/201913339Math: 56. C# - 그래프 그리기로 알아보는 경사 하강법의 최소/최댓값 구하기파일 다운로드1
11922정성태5/29/201911414.NET Framework: 840. ML.NET 데이터 정규화파일 다운로드1
11921정성태5/28/201916342Math: 55. C# - 다항식을 위한 최소 자승법(Least Squares Method)파일 다운로드1
11920정성태5/28/20199986.NET Framework: 839. C# - PLplot 색상 제어
11919정성태5/27/201913064Math: 54. C# - 최소 자승법의 1차 함수에 대한 매개변수를 단순 for 문으로 구하는 방법 [1]파일 다운로드1
11918정성태5/25/201914266Math: 53. C# - 행렬식을 이용한 최소 자승법(LSM: Least Square Method)파일 다운로드1
11917정성태5/24/201914322Math: 52. MathNet을 이용한 간단한 통계 정보 처리 - 분산/표준편차파일 다운로드1
11916정성태5/24/201912336Math: 51. MathNET + OxyPlot을 이용한 간단한 통계 정보 처리 - Histogram파일 다운로드1
11915정성태5/24/201914650Linux: 11. 리눅스의 환경 변수 관련 함수 정리 - putenv, setenv, unsetenv
11914정성태5/24/201914342Linux: 10. 윈도우의 GetTickCount와 리눅스의 clock_gettime파일 다운로드1
11913정성태5/23/201911984.NET Framework: 838. C# - 숫자형 타입의 bit(2진) 문자열, 16진수 문자열 구하는 방법파일 다운로드1
11912정성태5/23/201911635VS.NET IDE: 137. Visual Studio 2019 버전 16.1부터 리눅스 C/C++ 프로젝트에 추가된 WSL 지원
11911정성태5/23/201910746VS.NET IDE: 136. Visual Studio 2019 - 리눅스 C/C++ 프로젝트에 인텔리센스가 동작하지 않는 경우
11910정성태5/23/201919376Math: 50. C# - MathNet.Numerics의 Matrix(행렬) 연산 [1]파일 다운로드1
11909정성태5/22/201913843.NET Framework: 837. C# - PLplot 사용 예제 [1]파일 다운로드1
... 61  62  63  64  65  66  67  [68]  69  70  71  72  73  74  75  ...