<location>配置不从外部文件加载</location>

时间:2014-09-17 08:58:54

标签: asp.net-mvc web-config

从这两个帖子中获取灵感

我正在尝试加载我用于允许匿名访问的多个位置节点的配置。

<location configSource="AnonymousAccess.config" path="Content"></location>
<location configSource="AnonymousAccess.config" path="Scripts"></location>

我的AnonymousAccess.config中包含以下数据

<?xml version="1.0"?>
<location>
<system.web>
  <compilation debug="true" />
  <authorization>
    <allow users="*" />
  </authorization>
</system.web>
</location>

我将位置元素放在我从这个msdn链接确认的正确位置

enter image description here

我收到了配置错误&#39;。我该怎么做?

1 个答案:

答案 0 :(得分:1)

您不能在<location>元素上指定configSource属性,而是在<authorization><compilation>元素上指定。

请在此处查看相关问题:Specify more than one directory in Web.Config's Location Path element

<location path="Content">
  <system.web>
    <compilation configSource="AnonymousCompilation.config" />
    <authorization configSource="AnonymousAccess.config" />
  </system.web>
</location>
<location path="Scripts">
  <system.web>
    <compilation configSource="AnonymousCompilation.config" />
    <authorization configSource="AnonymousAccess.config" />
  </system.web>
</location>

你将拥有2个配置文件: AnonymousCompilation.config:

<compilation debug="true" />

和AnonymousAccess.config:

<authorization>
  <allow users="*" />
</authorization>