Bagaimana menambahkan Komentar di file web.config saat runtime di asp.net

pemrograman


Halo semuanya,

Hai, saya ingin menambahkan beberapa komentar di file web.config saya saat runtime.
Berarti misalnya

file Web.config asli adalah:

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>

Pada beberapa tombol klik, setelah itu diubah seperti :

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>

atau di mana pun di file web.config, komnet harus ditambahkan atau di bagian mana pun yang dikomentari, teks harus ditambahkan.
Apakah ini mungkin.
Tolong bantu aku.

Terima kasih untuk semuanya.

Salam,
Ranjeet Waje

Solusi 1

di mana pun di file web.config, komunikasi harus ditambahkan atau di bagian mana pun yang dikomentari, teks harus ditambahkan.
Apakah ini mungkin.

Mungkin, Ya! Tapi saya tidak menyarankan untuk melakukan itu sama sekali.

Web.Config adalah file konfigurasi berdasarkan menjalankan situs web Anda. Mengizinkan siapa pun (bahkan admin) untuk mengedit/memperbarui file konfigurasi akan memerlukan restart kumpulan aplikasi Anda yang akan menjadi masalah jika seseorang terhubung ke aplikasi Anda pada waktu yang sama di tempat lain. Lebih lanjut, menambahkan “komentar” ke file konfigurasi tidak terdengar penting atau diperlukan.

Jika Anda berpikir sebaliknya, cukup temukan/temukan file konfigurasi, dan temukan node dan perbarui seperti XML biasa. Pastikan Anda memiliki izin untuk mengedit/memperbarui file.

Solusi 2

Silakan lihat di WebConfigurationManager kelas[^]. Kelas ini pada gilirannya menyediakan akses ke kelas lain kelas[^], Configuration yang memungkinkan Anda bekerja dan mengedit file konfigurasi.

コメント

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