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();
    执行代码

    献丑献丑

  • 相关阅读:
    DC中为什么要用Uniquify?
    hdu 1596 find the safest road
    hdu2112 HDU Today
    hdu 2066 一个人的旅行
    poj 3026 Borg Maze
    poj 1979 Red and Black
    poj 1321 棋盘问题
    hdu 1010 Tempter of the Bone
    hdu 4861 Couple doubi
    codeforces584B Kolya and Tanya
  • 原文地址:https://www.cnblogs.com/ixysy/p/4961370.html
Copyright © 2011-2022 走看看