Cómo agregar comentarios en el archivo web.config en tiempo de ejecución en asp.net

programación


Estimados,

Hola, quiero agregar algunos comentarios en mi archivo web.config en tiempo de ejecución.
significa por ejemplo

El archivo Web.config original es:

C#
<pre lang="xml"><?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
    <appSettings>
  <add key="customsetting1" value="Some text here" />
  <add key="myKey" value=",1,1,1,1,1,1" />
  <add key="RemoveTCPError" value="1,1" />
 </appSettings>
    <connectionStrings>
  <add name="myDatabaseName" connectionString="whatever" />
 </connectionStrings>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true"/>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows"/>

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>

    </system.web>
</configuration>

Al hacer clic en algún botón, después de que se modificó como :

XML
<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->

<!--
    Note: As an alternative to hand editing this file you can use the
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->


<configuration>
    <appSettings>
  <add key="customsetting1" value="Some text here" />
  <add key="myKey" value=",1,1,1,1,1,1" />
  <add key="RemoveTCPError" value="1,1" />
 </appSettings>
    <connectionStrings>
  <add name="myDatabaseName" connectionString="whatever" />
 </connectionStrings>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true"/>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows"/>

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>

    </system.web>
</configuration>

o en cualquier lugar del archivo web.config se deben agregar comunicaciones o en cualquier parte comentada se debe agregar texto.
Es posible.
Por favor, ayúdame.

Gracias a todos de antemano.

Saludos,
Ranjeet Waje

Solución 1

En cualquier lugar del archivo web.config se deben agregar comunicaciones o en cualquier parte comentada se debe agregar texto.
Es posible.

Posible, ¡Sí! Pero no sugeriría hacerlo en absoluto.

Web.Config es un archivo de configuración basado en el que se ejecuta su sitio web. Permitir que cualquier persona (incluso el administrador) edite/actualice el archivo de configuración requeriría reiniciar su grupo de aplicaciones, lo que sería un problema si alguien está conectado a su aplicación al mismo tiempo en otro lugar. Además, agregar un “comentario” al archivo de configuración no parece ser una característica importante o necesaria en ninguna parte.

Si piensa lo contrario, simplemente busque/ubique el archivo de configuración, busque el nodo y actualícelo como un XML normal. Asegúrese de tener permiso para editar/actualizar el archivo.

Solución 2

Echa un vistazo a WebConfigurationManager clase[^]. Esta clase a su vez proporciona acceso a otra clase[^], Configuration lo que le permitirá trabajar y editar archivos de configuración.

コメント

タイトルとURLをコピーしました