asp.net - 将 configSource 与 NWebsec 结合使用

标签 asp.net web-config nwebsec

为了简化我们的 web.config,我想使用 configSource 属性将 NWebsec 配置分解为一个单独的文件:

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="nwebsec">
      <section name="httpHeaderSecurityModule" type="NWebsec.Modules.Configuration.HttpHeaderSecurityConfigurationSection, NWebsec, Version=4.2.0.0, Culture=neutral, PublicKeyToken=3613da5f958908a1" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <nwebsec configSource="App_Config\NWebsec.config" />
  <!--- remainder of file omitted for brevity -->
</configuration>

App_Config\NWebsec.config

<?xml version="1.0"?>
<nwebsec>
  <httpHeaderSecurityModule xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <redirectValidation enabled="true">
      <!-- omitted for brevity -->
    </redirectValidation>
    <securityHttpHeaders>
      <!-- omitted for brevity -->
    </securityHttpHeaders>
  </httpHeaderSecurityModule>
</nwebsec>

当我向应用程序发出请求时,我现在收到一个 HTTP 500 错误,没有其他详细信息。 Windows 事件查看器中也没有任何相关内容。

我尝试的操作可以通过 NWebsec 配置实现吗?

如何获取有关正在发生并导致 HTTP 500 响应的错误的更多详细信息?

最佳答案

我相信这是因为 nwebsec 元素被定义为 sectionGroup:

<sectionGroup name="nwebsec">
  <section name="httpHeaderSecurityModule" type="..." />
</sectionGroup>

configSource 属性仅适用于 section 元素。

修改web.config:

<nwebsec>
  <httpHeaderSecurityModule configSource="App_Config\NWebsec.config" />
</nwebsec>

除了修改引用文件的根元素 (App_Config\NWebsec.config) 之外,还可以使其按需要工作:

<?xml version="1.0"?>
<httpHeaderSecurityModule xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <redirectValidation enabled="true">
  ...

关于asp.net - 将 configSource 与 NWebsec 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53342371/

相关文章:

c# - 如何在 ASP.NET 中实现 Windows 服务类型的基础结构

c# - 查看从 View 到 Controller 的数据

c# - ASP.NET - MVC 4 使用从 Controller 到 View 的变量

c# - 如何在 Web 表单上输入值并将其作为数字存储在 SQL Server 中

c# - 如何避免在 web.config 中添加程序集版本?

xslt - 通过 configSource 链接到 web.config 的部分配置文件可以在 web 项目中转换吗?

ASP.NET 如何在 web.config 中添加程序集?