我没发现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' 的节是错误的。

他妈的,这就是一个不成熟的坑爹玩意儿。

原文地址:https://www.cnblogs.com/newsea/p/3774538.html