ASP.NET、WinForm、C# - 配置文件信息读取 [ Web.config || Appconfig ]

<configuration>

    <appSettings>
      <add key="name" value="HF_Ultrastrong"/>
    </appSettings>

    <connectionStrings>
      <add name="ConString" connectionString="server = ***; DATABASE = DB_News; integrated security = true"/>
    </connectionStrings>

</configuration>

获取配置文件中<appSettings>或是<connectionStrings>的值:

<appSettings>

//方法1
string Name = ConfigurationManager.AppSettings["name"].ToString();
//方法2
string Name = ConfigurationManager.AppSettings["name"];

<connectionStrings>

string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
时间: 2024-10-24 23:07:32

ASP.NET、WinForm、C# - 配置文件信息读取 [ Web.config || Appconfig ]的相关文章

MVC.Net:读取Web.config/App.config配置

需要读取Web.config/App.config的配置很简单,首先我们需要将配置写入到<appSettings>中,例如: <appSettings> <add key="thumbSize_weight" value="300"/> <add key="thumbSize_height" value="300"/> </appSettings> 读取配置语句(需要

来篇文章:ASP。NET程序中动态修改web.config中的设置项目 (后台CS代码)

朋友们可以自行测试,我这里都没有问题了,鳖了一上午的问题总算解决了 using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; usi

如何高逼格读取Web.config中的AppSettings

http://edi.wang/post/2015/4/22/how-to-read-webconfig-appsettings-with-bigiblity 先插句题外话,下版本的ASP.NET貌似把web.config撸掉了,都变成json了.所以本文讨论的内容可能以后用不到了,但是一些设计思想还是可以用的~ 直接进入正题,在ASP.NET网站里(也包括其他有web.config, app.config)的.NET工程里,读AppSettings的值是个很常见的场景.比如: <add key

asp.net设置默认打开页面,Web.config,defaultDocument

The web.config file can be used to set a default document, or list of default documents for your website. Web.config can be used to change the default document (page) for an entire site, or on a directory by directory basis. The default page may be a

ASP.NET添加、修改、删除web.config配置信息

1.导入命名空间? using System.Configuration; using System.Web.Configuration ; 2.输入代码? protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //保存在配置文件中 TextBox1.Text= WebConfigurationManager.AppSettings["xdsj"].ToString(); TextB

ASP.NET添加和读取Web.Config自定义配置节

自定义节 1.首先在<configSections>中定义自定义配置节(例如Index.testSection)和对应的自定义配置节处理程序(例如NameValueSectionHandler) 2.然后添加节的内容 <configuration> <configSections> <sectionGroup name="Rewrite.NET"> <section name="Index" type="

C# 读取web.config配置文件 读取连接字符串

1. <connectionStrings> <add name="mysql" connectionString="localhost" providerName="System.Data.SqlClient" /> </connectionStrings> string s = System.Web.Configuration.WebConfigurationManager.ConnectionString

读取web.config和app.config配置文件

app.config:       <add key="Password" value="123456"/> C#:   string TQpwd = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString(); 需要引用  using System.Configuration;

ASP.NET中禁止继承IIS中web.config根目录的配置

异常信息: Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Mes