SectionInformation.ForceSave Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece un valor que indica si se va a guardar la sección de configuración asociada aunque no se haya modificado.
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
Valor de propiedad
Es true
si se va a guardar el objeto ConfigurationSection asociado aunque no se haya modificado; de lo contrario, es false
. De manera predeterminada, es false
.
Nota: Si el archivo de configuración se guarda (incluso si no hay modificaciones), ASP.NET reinicia el application1.exe.config.
Ejemplos
En el ejemplo siguiente se muestra cómo usar la ForceSave propiedad de un ConfigurationSection objeto .
// 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