SectionInformation.ForceSave 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,指示是否将保存关联的配置节(即使它未被修改)。
public:
 property bool ForceSave { bool get(); void set(bool value); };public bool ForceSave { get; set; }member this.ForceSave : bool with get, setPublic Property ForceSave As Boolean属性值
如果将保存关联的 ConfigurationSection 对象(即使它未被修改),则为 true;否则为 false。 默认值为 false。
注意:如果配置文件 (保存,即使) 没有任何修改,ASP.NET 会重启 application1.exe.config。
示例
以下示例演示如何使用 ForceSave 对象的 属性 ConfigurationSection 。
// Create a section whose name is 
// MyUrls that contains a nested collection as 
// defined by the UrlsSection class.
static void CreateSection()
{
    string sectionName = "MyUrls";
    try
    {
        // Get the current configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);
        UrlsSection urlsSection;
        // Create the section whose name attribute 
        // is MyUrls in <configSections>.
        // Also, create the related target section 
        // MyUrls in <configuration>.
        if (config.Sections[sectionName] == null)
        {
            urlsSection = new UrlsSection();
            // Change the default values of 
            // the simple element.
            urlsSection.Simple.Name = "Contoso";
            urlsSection.Simple.Url = "http://www.contoso.com";
            urlsSection.Simple.Port = 8080;
            config.Sections.Add(sectionName, urlsSection);
            urlsSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);
        }
    }
    catch (ConfigurationErrorsException e)
    {
        Console.WriteLine("[CreateSection: {0}]",
            e.ToString());
    }
}
' Create a section whose name is 
' MyUrls that contains a nested collection as 
' defined by the UrlsSection class.
Shared Sub CreateSection()
    Dim sectionName As String = "MyUrls"
    Try
        ' Get the current configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)
        Dim urlsSection As UrlsSection
        ' Create the section whose name
        ' attribute isMyUrls in 
        ' <configSections>.
        ' Also, create the related target section 
        ' MyUrls in <configuration>.
        If config.Sections(sectionName) Is Nothing Then
            urlsSection = New UrlsSection()
            ' Change the default values of 
            ' the simple element.
            urlsSection.Simple.Name = "Contoso"
            urlsSection.Simple.Url = "http://www.contoso.com"
            urlsSection.Simple.Port = 8080
            config.Sections.Add(sectionName, urlsSection)
            urlsSection.SectionInformation.ForceSave = True
            config.Save(ConfigurationSaveMode.Full)
        End If
    Catch e As ConfigurationErrorsException
        Console.WriteLine("[CreateSection: {0}]", e.ToString())
    End Try
End Sub