ASP.NET 設定檔

來源:互聯網
上載者:User

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();
}
}
}

若有疑問或不正之處,歡迎提出指正和討論。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.