我正在處理一個巨大的MVC 4項目。我正在使用Area,它很棒。區域中的子Web.config
但是,我想爲每個區域使用自定義Web.config。
例如,這是我的結構:
Root
Web.config
|
----Areas
--------MyArea_1
--------MyArea_2
----Web.config
在我的根Web.config,我所有的連接。在我的Sub Web.config中,我想添加僅關注區域的「appSettings」。
在我的子Web.config文件,例如:
<appSettings>
<add key="MyArea_1_Param1" value="1"/>
<add key="MyArea_1_Param2" value="2"/>
<add key="MyArea_2_Param1" value="1"/>
</appSettings>
就目前而言,我已經把我所有的參數的根Web.config。
如何在不同的Web.config之間建立鏈接?
------ UPDATE --------
我嘗試把這個代碼在我的子Web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<location path="MyArea_1">
<appSettings>
<add key="MyArea_1_Param1" value="1"/>
<add key="MyArea_1_Param2" value="2"/>
</appSettings>
</location>
AI把這個文件,在這裏:
Root
Web.config
|
----Areas
--------MyArea_1
--------MyArea_2
----Web.config <- Here
我已經嘗試在這裏:
Root
Web.config
|
----Areas
--------MyArea_1
------------Web.config
--------MyArea_2
但我仍然得到一個「NullReferenceException異常」當我嘗試讀取密鑰值「MyArea_1_Param1」
我對讀取密鑰值碼:
ConfigurationManager.AppSettings["MyArea_1_Param1"].ToString()
請參閱我的更新。我試過,也許很糟糕,因爲我仍然有NullReferenceException錯誤。 – Portekoi
嗨看到我的更新回答 – Robert