다음을 통해 공유


SectionInformation.ForceSave 속성

정의

연결된 구성 섹션이 수정되지 않은 경우에도 저장되는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool ForceSave { bool get(); void set(bool value); };
public bool ForceSave { get; set; }
member this.ForceSave : bool with get, set
Public 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

적용 대상