2017-09-14 1 views
0

web.config 파일의 여러 섹션 값을 읽으 려합니다.web.config 파일의 값을 읽으십시오.

내가 httpRuntime을 requestValidationMode 값을 읽으려면이 system.web 섹션에서

<system.web> 
<compilation debug="true" targetFramework="4.5.2" /> 
<httpRuntime targetFramework="4.5.2" requestValidationMode="4.5" 
maxRequestLength="102400" /> 
<pages validateRequest="true"></pages> 
</system.web> 

. 페이지에서 validateRequest 값을 읽으 려합니다.

는 또한, 내가 당신을 믿지

<httpProtocol> 
    <customHeaders> 
    <add name="X-Content-Type-Options" value="nosniff" /> 
    <add name="X-Frame-Options" value="SAMEORIGIN" /> 
    <remove name="X-Powered-By" /> 
    <add name="X-XSS-Protection" value="1; mode=block" /> 
    </customHeaders> 
</httpProtocol> 

답변

0

다른 값이

ConfigurationSection httpProtocolSection = 
    ConfigurationManager.GetSection("system.webServer/httpProtocol"); 
ConfigurationElementCollection customHeadersCollection = httpProtocolSection.GetCollection("customHeaders");  

같은 것을 원하는 사용자 정의 헤더의 값을 읽고 싶어, 당신은 그 값이 저장되는 위치를 검색 할 수 있습니다 . 예를 들어

<compilation debug="true" ...> 

는 여기에 저장됩니다

HttpContext.Current.IsDebuggingEnabled 

은 섹션 종류의 많은, 또한, System.Web.Configuration

System.Web.Configuration.PagesSection 
System.Web.Configuration.HttpHandlersSection 

에 저장됩니다 그리고 당신은 (GetSection있는 사람을 검색 할 수 있습니다). = (AppSettingsSection) ConfigurationManager.GetSection ("customHeaders")와 VAR의 customHeaders = ConfigurationManager.GetSection ("customHeaders")로 NameValueCollection은 모두 널 값을 반환하는

+0

VAR의 customHeaders. – ABB

+0

내가 편집 했으므로, 그 부분의 XPath가 필요하다는 것을 깨달았다. –

+0

이 코드는 global.asax.cs에 있습니다. web.config 파일을 읽고 유효성을 검사하고 싶습니다. – ABB

관련 문제