web.config customErrors 섹션에 대한 참조를 얻으려고합니다. 다음 코드를 사용하면 항상 null이됩니다. 내가 만들었던 커스텀 섹션에 대한 참조를 얻을 때이 문제가 발생하지 않아서 이것이 왜 작동하지 않는지 조금 어이가 있습니다.ASP.NET web.config customErrors 섹션에 대한 참조 얻기
CustomErrorsSection customErrorSection =
ConfigurationManager.GetSection("customErrors") as CustomErrorsSection;
나는 또한이 시도했습니다
CustomErrorsSection customErrorSection =
WebConfigurationManager.GetSection("customErrors") as CustomErrorsSection;
나는이 시도했습니다 :
CustomErrorsSection customErrorSection =
WebConfigurationManager.GetWebApplicationSection("customErrors") as CustomErrorSection;
편집 :
아으! 질문을 한 직후에 대답을 찾은 대부분의 것들이 그러한 경우입니다.
이
나를 위해 작동합니다System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/");
CustomErrorsSection customErrorsSection = (CustomErrorsSection)configuration.GetSection("system.web/customErrors");
또는 더 간단하게 다음과 같이 :
CustomErrorsSection customErrors = (CustomErrorsSection) WebConfigurationManager.OpenWebConfiguration("/").GetSection("system.web/customErrors");
를 이것은 또한 작동합니다
CustomErrorsSection customErrorsSection = ConfigurationManager.GetSection("system.web/customErrors") as CustomErrorsSection;
그래서 나는 내가 있었다 왜 이제 이해 생각 문제가 처음이다. 나는 내가 customErrors 섹션에 대한 참조를 GetSection ("customErrors")을 시도함으로써 얻을 수 있다고 잘못 생각 했었지만 그것이 실제로 어떤 루트 섹션에 살았는지에 대해 알려주지 못했고, 내가 어떻게 알았는지에 대한 나의 시도를 근거로 삼았다. 내 커스텀 섹션이 섹션의 루트라는 사실을 깨닫지 못했을 때 커스텀 섹션을 얻어서 GetSection()을 호출 할 때 system.Web/앞에 앞에 붙일 필요는 없었습니다.
아마 바보 같은 질문을하지만, 섹션 설정 파일에 존재 하는가? – Oded
예 섹션이 있습니다. –
정당하고 다른 사람들을 도울 수 있습니다. 삭제하지 마십시오. – Oded