zoukankan      html  css  js  c++  java
  • C#中关于webconfig的读写

    近期一个小网站需要一个计数的信息

    偷懒不想用别的什么方法

    原本想用个xml 无奈不太会使

    虽然不推荐这种方法 不过还是记下来方便日后查看

    webconfig信息

     1 <?xml version="1.0"?>
     2 <!--
     3   有关如何配置 ASP.NET 应用程序的详细信息,请访问
     4   http://go.microsoft.com/fwlink/?LinkId=169433
     5   -->
     6 <configuration>
     7   <appSettings>
     8     <add key="num" value="658" />
     9   </appSettings>
    10   <!--
    11     有关 web.config 更改的说明,请参见 http://go.microsoft.com/fwlink/?LinkId=235367。
    12 
    13     可在 <httpRuntime> 标记上设置以下特性。
    14       <system.Web>
    15         <httpRuntime targetFramework="4.5" />
    16       </system.Web>
    17   -->
    18   <system.web>
    19 
    20   </system.web>
    21 </configuration>

    目标:对其节点num进行读写操作

    1 string num = ConfigurationManager.AppSettings["num"].ToString();
    2             Configuration objconfig = WebConfigurationManager.OpenWebConfiguration("~");
    3             AppSettingsSection objsets = (AppSettingsSection)objconfig.GetSection("appSettings");
    4 
    5             objsets.Settings["num"].Value = (int.Parse(num) + 1).ToString();
    6             objconfig.Save();
    执行代码

    献丑献丑

  • 相关阅读:
    团队开发5
    团队开发4
    团队开发3
    团队开发2
    团队开发1
    团队计划会议
    寒假学习进度---完结篇
    寒假学习进度十七
    寒假学习进度十六
    python后续学习
  • 原文地址:https://www.cnblogs.com/ixysy/p/4961370.html
Copyright © 2011-2022 走看看