如何在asp.net中的运行时在web.config文件中添加Comment [英] How add Comment in web.config file at runtime in asp.net

查看:117
本文介绍了如何在asp.net中的运行时在web.config文件中添加Comment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我想在运行时在我的web.config文件中添加一些注释。

表示例如



原始Web.config文件是:



Dear All,

Hi, I want add some comments in my web.config file at runtime.
Means for example

original Web.config file is:

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







开一些按钮点击,修改后像






On some Button click,after it modified like :

<?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文件中的任何文件应该添加或应添加任何注释的部分文本。

这是可能的。

请帮助我。



感谢所有提前。



问候,

Ranjeet Waje




or any where in the web.config file commnets should be added or in any commented part text should be added.
Is this possible.
Please,Help me.

Thanks to all in Advance.

Regards,
Ranjeet Waje

推荐答案

网络中的任何位置。应添加配置文件通用或添加任何注释部分文本。

这是可能的。


可能,是的!但我根本不建议这样做。



Web.Config是一个基于您的网站运行的配置文件。允许任何人(甚至管理员)编辑/更新配置文件都需要重新启动应用程序池,如果有人在其他地方同时连接到您的应用程序,则会出现问题。此外,在配置文件中添加注释并不是任何重要或必要的功能。



如果您不这么认为,只需查找/找到配置文件,找到该节点并将其更新为普通XML。请确保您有权编辑/更新文件。
any where in the web.config file commnets should be added or in any commented part text should be added.
Is this possible.

Possible, Yes! But I would not suggest to do it at all.

Web.Config is a configuration file based on which your website is running. Allowing anyone(even admin) to edit/update config file would need a restart of your application pool which would be an issue if someone is connected to your app at the same time somewhere else. Further, adding a "comment" to config file does not sounds anywhere important or necessary feature.

If you think otherwise, just find/locate the config file, and find the node and update it just as a normal XML. Do make sure, you have permission to edit/update the file.


查看 WebConfigurationManager class [ ^ ]。该类反过来提供对另一个的访问[ ^ ],配置这将允许您工作和编辑配置文件。
Have a look at the WebConfigurationManager class[^]. This class in turn provides access to another class[^], Configuration which will allow you to work and edit config files.


这篇关于如何在asp.net中的运行时在web.config文件中添加Comment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆