アプリケーションにカスタム ConfigurationSection があります。
public class SettingsSection : ConfigurationSection
{
[ConfigurationProperty("Setting")]
public MyElement Setting
{
get
{
return (MyElement)this["Setting"];
}
set { this["Setting"] = value; }
}
}
public class MyElement : ConfigurationElement
{
public override bool IsReadOnly()
{
return false;
}
[ConfigurationProperty("Server")]
public string Server
{
get { return (string)this["Server"]; }
set { this["Server"] = value; }
}
}
私のweb.configで
<configSections>
<sectionGroup name="mySettingsGroup">
<section name="Setting"
type="MyWebApp.SettingsSection"
requirePermission="false"
restartOnExternalChanges="true"
allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
<mySettingsGroup>
<Setting>
<MyElement Server="serverName" />
</Setting>
</mySettingsGroup>
セクションを読むとうまくいきます。私が抱えている問題は、セクションを読んだときに
var settings = (SettingsSection)WebConfigurationManager.GetSection("mySettingsGroup/Setting");
Server次に、プロパティの変更に進みます。
settings.Server = "something";
これは、web.config ファイルの "Server" プロパティを変更しません。
注: これは中程度の信頼で動作する必要があるため、WebConfigurationManager.OpenWebConfiguration正常に動作するものは使用できません。ConfigSection自分自身を保存するように指示する明示的な方法はありますか?