ASP.NET 配置文件 - IceKnp - 博客园
来源:百度文库 编辑:神马文学网 时间:2024/04/26 03:53:39
ASP.NET 配置文件
1.ASP.NET配置文件采用继承关系,其关系是:是machine.config-->web.config-->文件夹web.config。
2.关于
3.关于lockAttributes,lockElements,lockAllAttributesExcept,lockAllElementsExcept属性,其表示锁定某个属性或节点,继承于其配置文件的将不能重写该属性,如:
4.关于配置文件的读写,首先对配置文件进行读取,我们都知道配置文件是一个XML文件,我们可以采用读取XML方式进行读写操作,但是,在ASP.NET中,MS提供了一套强类型的API对配置文件进行读写操作,如:
读取操作:
using System.Web.Configuration;
using System.Configuration;
namespace ConfingDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MembershipSection ms = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership", "~/web.config");
Response.Write("The default provider as set in config is: " +
ms.DefaultProvider + "
");
}
}
}
写入操作:
using System.Web.Configuration;
using System.Configuration;
namespace ConfingDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
MembershipSection ms = (MembershipSection)config.GetSection("system.web/membership");
ms.DefaultProvider = "someOtherProvider";
config.Save();
}
}
}