在ASP.NET访问的app.configNET、ASP、config、app

2023-09-04 11:49:57 作者:ご壊吖头)

我使用app.config文件读取它的数据.. 我加载app.config文件为:

I am using app.config file to read data from it.. I am loading the app.config file as:

string app_path = HttpContext.Current.Server.MapPath("app.config");
xmlDoc.Load(app_path);

string image_path = ConfigurationManager.AppSettings["Test1"];

和我想测试1的值。但TEST1的值正在添加空.. 我怎样才能测试1从app.config文件的价值.. 我创建了app.config文件为:

and i want to get the value of "Test1". But the value of test1 is comming "null".. how can i get the value of "test1" from app.config file.. i created the app.config file as:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="Test1" value="My value 1" />
    <add key="Test2" value="Another value 2" />
  </appSettings>
</configuration>

请帮我..

推荐答案

在ASP.NET应用程序,默认的配置文件名为web.config中。这是一个约定,你或许应该坚持,这让您轻松使用 ConfigurationManager中来访问配置设置。

In ASP.NET applications, the default configuration file is named web.config. This is a convention you should probably stick to, that allows you to easily use the ConfigurationManager to access configuration settings.

我建议在看看 http://en.wikipedia.org/wiki/Web.config 以此为出发点,以了解在ASP.NET领域的基本.NET应用程序配置的来龙去脉。

I suggest having a look at http://en.wikipedia.org/wiki/Web.config as a starting point to learn the ins and outs of basic .NET application configuration in the ASP.NET domain.

您可以链接配置文件一起,通过设置文件要覆盖的配置部分属性:http://www.$c$cproject.com/KB/dotnet/appsettings_fileattribute.aspx

You can link configuration files together, by setting the file attribute of configuration sections you want to override: http://www.codeproject.com/KB/dotnet/appsettings_fileattribute.aspx

 
精彩推荐
图片推荐