كيفية إضافة تعليق في ملف web.config في وقت التشغيل في asp.net

برمجة


أعزائي،

مرحبًا، أريد إضافة بعض التعليقات في ملف web.config الخاص بي في وقت التشغيل.
يعني مثلا

ملف Web.config الأصلي هو:

ج #
<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>

في بعض النقر على الزر، بعد تعديله مثل :

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>

أو في أي مكان في ملف web.config يجب إضافة commnets أو يجب إضافة نص في أي جزء تم التعليق عليه.
هل هذا ممكن.
الرجاء مساعدتي.

شكرا للجميع مقدما.

يعتبر،
رانجيت واجي

الحل 1

يجب إضافة commnets في أي مكان في ملف web.config أو يجب إضافة نص في أي جزء تم التعليق عليه.
هل هذا ممكن.

ممكن، نعم! لكنني لا أقترح القيام بذلك على الإطلاق.

Web.Config هو ملف تكوين يتم تشغيل موقع الويب الخاص بك بناءً عليه. إن السماح لأي شخص (حتى المسؤول) بتحرير/تحديث ملف التكوين سيحتاج إلى إعادة تشغيل مجمع التطبيقات الخاص بك والذي قد يمثل مشكلة إذا كان شخص ما متصلاً بتطبيقك في نفس الوقت في مكان آخر. علاوة على ذلك، فإن إضافة “تعليق” إلى ملف التكوين لا يبدو ميزة مهمة أو ضرورية في أي مكان.

إذا كنت تعتقد خلاف ذلك، فما عليك سوى العثور على/تحديد موقع ملف التكوين، والعثور على العقدة وتحديثها تمامًا مثل ملف XML العادي. تأكد من أن لديك الإذن لتحرير/تحديث الملف.

الحل 2

الق نظرة على WebConfigurationManager فصل[^]. توفر هذه الفئة بدورها إمكانية الوصول إلى فئة أخرى فصل[^], Configuration والتي سوف تسمح لك بالعمل وتحرير ملفات التكوين.

コメント

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