【问题标题】:REMOTE_ADDR disappears when running XSLT运行 XSLT 时 REMOTE_ADDR 消失
【发布时间】:2018-11-08 15:56:50
【问题描述】:

我为我的网站创建了一个阻止规则,其中列出了一些允许访问我网站的管理页面的 IP 地址。 条件如下所示:

<xsl:template match="/configuration/system.webServer/rewrite/rules/rule[@name='adminBlockRule']">
    <xsl:comment>Blockera Admin för alla utom vissa IP-adresser</xsl:comment>
    <rule name="adminBlockRule" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="^(Admin/|Sysadmin/).*$" ignoreCase="true"/>
      <conditions>
        <xsl:comment>Generell</xsl:comment>
        <add input="{REMOTE_ADDR}" pattern="10.*.*.*" negate="true" />
        <add input="{REMOTE_ADDR}" pattern="194.103.31.*" negate="true" />
        ... More rules
      </conditions>
      <action type="AbortRequest" />
    </rule>
    <xsl:comment>Hit</xsl:comment>
  </xsl:template>

当我把它放在我的 web.config 文件中时,它工作正常,但是当我把它放在我的 web.production.config 文件中并使用 XSLT 运行它时,它会删除“{REMOTE_ADDR}”,所以输出看起来像这样:

<rule name="adminBlockRule" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^(Admin/|Sysadmin/).*$" ignoreCase="true" />
          <conditions>
            <!--Generell-->
            <add input="" pattern="10.*.*.*" negate="true" />
            <add input="" pattern="194.103.31.*" negate="true" />
          </conditions>
          <action type="AbortRequest" />
        </rule>

有人知道如何解决这个问题吗?

我正在使用版本:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:saml="urn:dk.nita.saml20.configuration"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl saml">
  <xsl:output method="xml"
              indent="yes"/>
  <xsl:strip-space elements="*"/>

【问题讨论】:

  • 您应该编辑您的问题以显示您正在使用的 XSLT,因为在 cmets 中代码很难阅读。另外,您能否显示设置了REMOTE_ADDR 的XML。谢谢。
  • @TimC 感谢您的评论,我已经更新了我的问题。希望我正确理解了您的反馈。

标签: xml xslt web-config rules transformer


【解决方案1】:

我通过在输入参数中添加一对额外的“{}”解决了我的问题,并且成功了。 新条件如下所示:

<add input="{{REMOTE_ADDR}}" pattern="10.*.*.*" negate="true" />
<add input="{{REMOTE_ADDR}}" pattern="194.103.31.*" negate="true" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 2020-12-20
    • 2011-12-15
    • 2019-06-16
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多