【问题标题】:Can I make a monoSettings section in a web.config file optional to run on Windows as well as under Mono?我可以在 web.config 文件中创建一个可选的 monoSettings 部分以在 Windows 和 Mono 下运行吗?
【发布时间】:2016-09-22 17:52:51
【问题描述】:

我不得不在我的 Web.config 文件中添加一个 monoSettings 部分,因为我需要在 url 中支持冒号(类似于这个问题:ASP.NET special characters in URL (colon) not working even with requestPathInvalidCharacters="")。

现在,当我在 Visual Studio 中运行我的 web-api 服务(我为临时测试执行此操作)时,它给出了一个错误: “无法读取配置节‘monoSettings’,因为它缺少节声明”

我只是想知道在我的 Mono 服务中支持此配置而不影响在 Windows 上运行的最佳方式是什么?我可以将其标记为可选或不重要,以便在尝试读取配置时不会失败?或者,为 Mono 提供不同的构建配置是否更好 - 但我必须维护两个版本的 web.config,只有这一点细微差别。

【问题讨论】:

标签: c# asp.net-web-api mono


【解决方案1】:

我通过向我的 Web.config 添加一个 configSection 解决了这个问题,如下所示:

<configuration>
  <configSections> 
    <sectionGroup name="system.web">
      <section name="monoSettings" type="DataSetSectionHandler,SectionHandlers" />
    </sectionGroup>
  </configSections>
  <system.web>
    <monoSettings verificationCompatibility="1" />
    <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?" />
  </system.web>
</configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 2022-08-15
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    相关资源
    最近更新 更多