単純なはずですが、私が試したものはすべてnullを返します。
const string key = "system.web";
var sectionTry1 = WebConfigurationManager.GetSection(key);
var sectionTry2 = ConfigurationManager.GetSection(key);
私は以前にこれを行ったことがあると確信しています。
これが違いを生むのであれば、私はMVCを使用しています。
単純なはずですが、私が試したものはすべてnullを返します。
const string key = "system.web";
var sectionTry1 = WebConfigurationManager.GetSection(key);
var sectionTry2 = ConfigurationManager.GetSection(key);
私は以前にこれを行ったことがあると確信しています。
これが違いを生むのであれば、私はMVCを使用しています。
ばかだった-system.webは構成セクションではなく、構成グループです。キーを実際のセクションに変更すると、どちらの方法でも問題なく機能します。これがConfigurationManagerを使用しているものです。
const string outputCacheSettingsKey = "system.web/caching/outputCacheSettings";
var outputCacheSettingsSection = ConfigurationManager.GetSection(outputCacheSettingsKey) as OutputCacheSettingsSection;
system.webへのアクセスは、appSettingsへのアクセスとは少し異なると思います。
これを試して:
string configPath = "/MyAppRoot";
Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
IdentitySection section = (IdentitySection)config.GetSection("system.web/identity");
特定のタイプにアクセスしようとしているsystem.webの関連セクションをキャストする必要があります。
これは私のために働いた:
public Int32 GetmaxRequestLength()
{
// Set the maximum file size for uploads in bytes.
var section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
// return length converted to kbytes or return default value as specified
return (Int32) Math.Round((decimal)(section != null ? (double)section.MaxRequestLength * 1024 / 1000 : 5.120), 2);
}