【问题标题】:How to URL rewrite formaction for button using IIS 8.5如何使用 IIS 8.5 重写按钮的 URL 操作
【发布时间】:2019-09-04 10:59:15
【问题描述】:

我的服务器上运行着一个 ASP.NET Core 2.2 网站

mydomain.com/foo

哪个指向

localhost:83

一切似乎都使用 URL 重写规则重写了:

<outboundRules>
    <rule name="ReverseProxyOutboundRule" stopProcessing="false">
        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^(http)?(s)?(://)?localhost:83/(.*)" />
        <action type="Rewrite" value="http{R:1}://mydomain.com/foo/{R:4}" />
    </rule>
    <rule name="Relative" enabled="true">
        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)$" />
        <action type="Rewrite" value="/foo/{R:1}" />
        <conditions>
            <add input="{REQUEST_URI}" pattern="^/foo(.?)" />
        </conditions>
    </rule>
</outboundRules>

几乎所有东西,除了我的&lt;button&gt;

<button class="btn btn-danger" type="submit" formaction="/dummy/mypage?handler=Delete">Delete</button>

我期望的应该是这样的:

<button class="btn btn-danger" type="submit" formaction="/foo/dummy/mypage?handler=Delete">Delete</button>

我尝试将我的按钮添加为custom tag

<outboundRules>
    <rule name="ReverseProxyOutboundRule" stopProcessing="false">
        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script, CustomTags" customTags="Misc" pattern="^(http)?(s)?(://)?localhost:83/(.*)" />
        <action type="Rewrite" value="http{R:1}://mydomain.com/foo/{R:4}" />
    </rule>
    <rule name="Relative" enabled="true">
        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script, CustomTags" customTags="Misc" pattern="^/(.*)$" />
        <action type="Rewrite" value="/foo/{R:1}" />
        <conditions>
            <add input="{REQUEST_URI}" pattern="^/foo(.?)" />
        </conditions>
    </rule>
    <customTags>
        <tags name="Misc">
            <tag name="button" attribute="formaction" />
        </tags>
    </customTags>
</outboundRules>

但它似乎对我没有任何作用。

我实际上希望 URL 重写能够自动支持 &lt;button&gt; 的重写。

谁能说出这里缺少什么?


更新
添加了一个我没有看到相关性的相对规则。问题还是一样,我的&lt;button&gt; 元素上的formaction 没有被重写。

【问题讨论】:

    标签: url-rewriting reverse-proxy asp.net-core-2.2 iis-8.5


    【解决方案1】:

    您的 url rewrtie 规则模式似乎有问题。

    我建议你可以尝试使用下面的 url 重写规则并再次测试。

            <outboundRules>
                <rule name="aa">
                    <match filterByTags="CustomTags" customTags="MSC" pattern="/dummy/mypage" />
                    <action type="Rewrite" value="/foo/dummy/mypage?handler=Delete" />
                </rule>
                <customTags>
                    <tags name="MSC">
                        <tag name="button" attribute="formaction" />
                    </tags>
                </customTags>
            </outboundRules>
    

    结果:

    【讨论】:

    • 您能否详细说明一下为什么我的重写模式是错误的?它似乎确实适用于我网站上的所有其他内容 - 只是不适用于我的 buttons 中的 formactions。
    • 由于您的 url 重写规则包含“?”在部分中,这就是您的规则不起作用的原因。在正则表达式中?被视为“标记表示前面元素出现零次或一次”。
    • 我不明白为什么模式中的 ? 会影响这一点。然而,我确实看到,我省略了一个相对路径的规则,我现在已经包含了它。我需要从端口 83 映射到 foo 的第一条规则。第二种是重写相对url,以防请求来自foo
    猜你喜欢
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    相关资源
    最近更新 更多