首页 文章

使用IIS Url Rewrite 2.0和ARR重写自定义标记属性

提问于
浏览
4

我开发了一个自定义网格控件,它使用 data-* 属性来配置网格应该如何工作(与Bootstrap数据API组件的工作方式类似 . 对于特定部署,我当前正在尝试配置出站规则重写网址以匹配 . 例如,我目前有规则设置,例如:

  • 通过更新 Location: 标头重写HTTP重定向 .

  • 为标准标签中的URI重写Html内容(例如,A,区域,基础等)

  • 重写相对URI的Css内容(例如/cassette.axd - > /blog/cassette.axd) .

我遇到的最后一个问题是让URL重写模块在数据属性中接受我的网址,例如,如果我的网格是这样的:

<table data-grid data-query="/api/users/">

应改写为

<table data-grid data-query="/blog/api/users/">

我强调所有其他标记,例如 <a href<img src 按预期工作,甚至自定义 <property value 标记也会被正确重写 . 似乎只是通过夸大的属性 .

我已经尝试添加 <customTags> 部分,我的自定义标记位于:

<customTags>
    <tags name="Bootgrid">
        <tag name="table" attribute="data-query" />
        <tag name="table" attribute="data-update" />
        <!-- This next tag WORKS -->
        <tag name="property" attribute="value" />
    </tags>
</customTags>

但是,上述内容不匹配任何带连字符的属性 . 不确定这是否真的可以解决,因为我在IIS配置中看不到任何设置这些内容 .

还烦人的是,一旦你在IIS中创建了一组自定义标签,你似乎无法再次编辑它们 . : - /

3 回答

  • 0

    我有同样的问题,它似乎(虽然没有得到Microsoft确认)IIS无法处理包含 - 的自定义标记 -

    解决这个问题的方法是使用另一个出站规则 . 在此示例中,我尝试替换img标记中的data-zoom-image属性(您需要在"match"和"action"中将 <img 替换为 <tabledata-zoom-imagedata-query

    <rule name="RewriteRelativePathsCustomTags1" preCondition="IsHtml" enabled="true">
        <match filterByTags="None" pattern="&lt;img ([^>]*)data-zoom-image=&quot;(.*?)&quot;([^>]*)>" />
        <action type="Rewrite" value="&lt;img {R:1}data-zoom-image=&quotYOUR VALUE TO REWRITE i.e /blog{R:2}&quot;{R:3}>" />
    </rule>
    <preConditions>
        <preCondition name="IsHtml">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
        </preCondition>
    </preConditions>
    

    希望这可以帮助

  • 1

    IIS上的ARR似乎存在标记问题,其中包含带有短划线( - )的属性 .

    更新到v3.0.1952似乎已经解决了我的问题,但我仍在调查 .

  • 0

    相反,但是在Release To Web版本(2.0.1952)中这是fixed back in 2015

    重要信息 - 此版本中的更改Windows 10和Windows Server 2016支持 - 现在可以在此版本的Windows 10或Windows Server 2016上安装URL重写模块2.0现在支持包含短划线的自定义属性 . 这是必需的,因为HTML 5具有以下用于确定HTML属性名称的规则:http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes包含URL Rewrite 2.0的修补程序(2014年6月)as在KB2974666

相关问题