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の値を読み取る必要があります。
はまた、私はあなたが他の値については、この
ConfigurationSection httpProtocolSection =
ConfigurationManager.GetSection("system.webServer/httpProtocol");
ConfigurationElementCollection customHeadersCollection = httpProtocolSection.GetCollection("customHeaders");
ような何かをしたいと考えているカスタムヘッダーの値
<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>
NameValueCollectionのようなVARのcustomHeaders =(AppSettingsSection)ConfigurationManager.GetSection( "customHeaders")と VaRのcustomHeaders = ConfigurationManager.GetSection( "customHeaders")の両方がヌル値を戻すしています。 – ABB
私はそれを編集しました。私はそれのためのセクションのXPathが必要であることを理解しました。 –
私はこのコードをglobal.asax.csに書いています。私はweb.configファイルを読んでそれを検証したいです – ABB