天天看點

我沒發現Mvc裡的 web.config 有什麼用。實驗過程結果分析

由于 Mvc2+ 引入 Area ,導緻檔案夾結構發生變化。 Mvc下的 web.config 所在的位置是:

~/Areas/MySystem/Views/Web.config

對應的請求的URL是:

~/MySystem/Home/Index

這時, 在根目錄下添加 AppSetting 項:

    <add key="AdminUserId"

value="LhlcAdministator"/>

在 ~/Areas/MySystem/Views/Web.config 覆寫 根下的 AdminUserId

  <remove key="AdminUserId" />

    <add key="AdminUserId" value="Host"/>

在 ~/MySystem/Home/Index 對應的Action 寫如下代碼:

  return Content(

System.Configuration.ConfigurationManager.AppSettings["AdminUserId"].ToString()

);

期望的結果是: Host

結果輸出的是根Web.config配置結果: LhlcAdministator

調試發現,把 ~/Areas/MySystem/Views/Web.config 轉移到  ~/MySystem/Web.config 下可以。

但是如果在  ~/Areas/MySystem/Views/Web.config 下添加:

  <system.web>

    <authentication

mode="Forms">

      <forms loginUrl="~/Login"

timeout="2880" />

    </authentication>

</system.web>

則會報: 在應用程式級别之外使用注冊為 allowDefinition=‘MachineToApplication‘ 的節是錯誤的。

他媽的,這就是一個不成熟的坑爹玩意兒。