`

vs.net 2005中的ConfigurationManager

    博客分类:
  • .NET
阅读更多
vs.net 2005中的ConfigurationManager,代替了原来的configurationsettings。用法大概如下,详细的看MSDN
读取配置:
ConfigurationManager.AppSettings["MyKey"]

读取数据库的配置(这个估计大家最经常用了)
 在web.config中
<connectionStrings>

  <add name="AppConnectionString1" connectionString="server=localhost;database=northwind;uid=sa;password=xxxx;"/>
 </connectionStrings>

在程序中如下读取:
  SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);

GETSECTION方法:
 ConfigurationManager.GetSection("mySection")
其他的方法大概描述摘录如下:

GetWebAppSection

<!----><o:p> </o:p>

With the GetWebAppSection you can get the specified section from the web applications configuration file.

<o:p> </o:p>

Note: This method retrieves the specified configuration section from the configuration file located at the root folder of your Web application. If you want to retrieve the configuration section from the current Web application directory use the GetSection method.

<o:p> </o:p>

RefreshSection

<o:p> </o:p>

RefreshSection will refresh the specified section so next time its requested, it will be re-read from disk.

<o:p> </o:p>

With the following method, you will have the ability to programmatically change the settings within the configuration files. Those methods will return a Configuration class (The Configuration class has properties to get sections from the configuration file you want to edit, and by using the Save or SaveAs method, you can save the settings):

<o:p> </o:p>

OpenMachineConfiguration

<o:p> </o:p>

With the OpenMachineConfiguration, you configure the machine.config file.

<o:p> </o:p>

OpenMappedMachineConfiguration

<o:p> </o:p>

With the OpenMappedMachineConfiguration, you can open a specified configuration file.

<o:p> </o:p>

OpenExeConfiguration

<o:p> </o:p>

With the OpenExeConfiguration, you can open the client’s configuration file.

<o:p> </o:p>

OpenMappedExeConfiguration

<o:p> </o:p>

With the OpenMappedExeConfiguration, you can open the specified client configuration.

 

OpenWebConfiguration

<o:p> </o:p>

With the OpenWebConfiguration, you can open the web applications configuration file.

 

OpenMappedWebConfiguration

<o:p> </o:p>

With the OpenMappedWebConfiguration, you can open a specified web configuration file.

分享到:
评论

相关推荐

    asp.net 类库中使用ConfigurationManager.ConnectionStrings

    一直没弄明白怎么在类库中找不到 ConfigurationManager.ConnectionStrings 后面才发现没有添加System.configuration的引用,添加后: 引入命名空间: 代码如下:using System.Configuration; 便可以使用了: 代码如下...

    .NET的简单ConfigurationManager

    中小型项目的配置管理组件

    Net Core全局配置读取管理方法ConfigurationManager

    主要为大家详细介绍了Net Core全局配置读取管理方法ConfigurationManager的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    apollo.net:Apollo配置中心.Net客户端

    一、框架集成与集成请参考,完全支持IConfiguration的变动通知与集成(.net 4.7.1及以后版本,只支持动态修改ConfigurationManager.AppSettings)或直接使用ApolloConfigurationManager请参考如果想将传统的config配置...

    asp.net2.0中对config文件的操作方法总结

    在.net编程中,我们经常用到config文件...这个.config文件其实就是一个xml文件,对它的读操作微软已经提供了一个类来实现了,这个类就是System.Configuration.ConfigurationManager,下面分别是例子:.................

    Dunk.Tools.Configuration:提供.NET Framework ConfigurationManager的包装器接口

    Dunk.Tools.Configuration 提供.NET Framework ConfigurationManager的包装器接口

    c#读写App.config,ConfigurationManager.AppSettings 不生效的解决方法

    主要介绍了c#读写App.config,ConfigurationManager.AppSettings 不生效的解决方法,需要的朋友可以参考下

    ASP.NET MVC分页HtmlHelper 2010贺岁版

    故需改为private static int PageSize = int.Parse(ConfigurationManager.AppSettings["PageSize "]); **private static int DisplaySize = int.Parse (ConfigurationManager.AppSettings["DisplaySize"]);

    ASP.NET core Web中使用appsettings.json配置文件的方法

    移植代码基本顺利,但是发现.net core中没有ConfigurationManager,无法读写配置文件,单独写个xml之类的嫌麻烦,就谷歌了下,发现了个方法,遂记录如下,方便以后查找: 方法如下 配置文件结构 public class ...

    sccmclictr:Configuration Manager客户中心

    Configuration Manager的客户中心提供了快速简便的客户端设置概述,包括在良好且易于使用的用户界面中运行服务和代理设置。 资料下载 离线安装程序 ClickOnce设置 MSIX设定 包管理器 Windows 10商店 文献资料 ...

    不要使用ConfigurationManager!

    如果您是在类中间使用ConfigurationManager.AppSettings的那些开发人员之一,那么请停止,请停止。

    ASP.NET相册控件(含源码)

    smallfoldername = Server.MapPath(ConfigurationManager.AppSettings["SmallPath"]); bigfoldername = Server.MapPath(ConfigurationManager.AppSettings["NormalPath"]); } catch { smallfoldername = ...

    Syncfusion.Report.Net.Core破解版

    csdn无法免积下载,只能选最少的1个积分了 使用最新的16.3.0.36版本,含: Syncfusion.Compression.Portable Syncfusion.DocIO.Portable.dll ...System.Configuration.ConfigurationManager System.Data.SqlClient

    asp.net登陆源码

    string myStr = ConfigurationManager.ConnectionStrings["DataBaseConnectionString4"].ToString(); SqlConnection myConn = new SqlConnection(myStr); SqlCommand myCmd = new SqlCommand("select count(*) ...

    ExtJS .net分页例子

    con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;//ConnectionString con.Open(); SqlCommand cmd = new SqlCommand(); cmd....

    .NET Core日志配置的方法

    而要在代码中获得文件中的配置信息,ConfigurationManager则是必不可少需要引入的程序集。 然而到了ASP.NET Core时代,存储与读取配置的方式都发生了改变。 如果对ASP.NET Core项目有所了解的话,应该会看到过...

    asp.net基于XML的留言板

    SqlConnection mycon = new SqlConnection(ConfigurationManager.AppSettings["ConSQL"]); mycon.Open(); string cmdtxt2 = "SELECT * FROM tb_Reply WHERE ReplyID='" + Request["ID"].ToString() + "'"; ...

    ado.net简单操作实例 一看就入门

    static string constr = ConfigurationManager.ConnectionStrings["tblConnectionString"].ConnectionString.ToString(); SqlConnection conn = new SqlConnection(constr); conn.Open(); SqlCommand cmd = new ...

    FCKeditor 网页文本编辑器(asp.net)

    FCKeditor 网页文本编辑器(asp.net),使用的时候注意设置页面的属性ValidateRequest="false"。 1.引用FredCK.FCKeditorV2.dll。 2.打开网站,选择工具箱,找到其中 常规 选项卡 ,点击右键选择 --&gt;选择项---&gt;浏览 ...

Global site tag (gtag.js) - Google Analytics