在 ASP.NET 中访问 app.config [英] Accessing app.config in ASP.NET
问题描述
我正在使用 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"];
我想获得Test1"的值.但是 test1 的值是空"..我如何从 app.config 文件中获取test1"的值..我将 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.
您可以通过设置要覆盖的配置部分的 file
属性将配置文件链接在一起:http://www.codeproject.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
这篇关于在 ASP.NET 中访问 app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!