1.ASP.NET設定檔採用繼承關係,其關係是:是machine.config-->web.config-->檔案夾web.config。
2.關於<location/>節點節點,通常在配置許可權時候,我們使用web.config對網站目錄下檔案夾或檔案進行一個許可權的限定訪問,如:
<!--表示對檔案夾admin1進行限制-->
<location path="admin1">
<system.web>
<authorization>
<allow roles="-100,1,2"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<!--表示對檔案夾admin2以及檔案admin2.aspx進行限制-->
<location path="admin2\admin2.aspx">
<system.web>
<authorization>
<allow roles="-100,3,4"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
3.關於lockAttributes,lockElements,lockAllAttributesExcept,lockAllElementsExcept屬性,其表示鎖定某個屬性或節點,繼承於其設定檔的將不能重寫該屬性,如:
<membership lockElements="providers" lockAttributes="defaultProvider,hashAlgorithmType">
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 + "<br/>");
}
}
}
//寫入操作:
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();
}
}
}
若有疑問或不正之處,歡迎提出指正和討論。