【问题标题】:Web config redirect rule to the same action with another query string parametersWeb config 将规则重定向到具有另一个查询字符串参数的相同操作
【发布时间】:2013-06-05 15:04:03
【问题描述】:

好吧,在我的 C# ASP .Net MVC 应用程序中,我有一个 URL:

controller/action?parameter=value

我需要使用重写规则将 web.config 中的这个 URL 重定向到:

controller/action?parameter=anotherValue

我已经配置了必要的部分,如下所示:

<rule name="Redirect" patternSyntax="Wildcard" stopProcessing="true">
    <match url="controller/action?parameter=value" />
    <action type="Redirect" url="controller/action?parameter=anotherValue" />
</rule>

但是这条规则是行不通的。我也试过了:

<rule name="Redirect" patternSyntax="Wildcard" stopProcessing="true">
    <match url="controller/action$" />
    <conditions>  
        <add input="{QUERY_STRING}" pattern="parameter=value" />  
    </conditions> 
    <action type="Redirect" url="controller/action?parameter=anotherValue" redirectType="Permanent" />

但这条规则将我重定向到:controller/action?parameter=value&amp;parameter=anotherValue

如何正确执行此重定向?

【问题讨论】:

    标签: c# asp.net-mvc redirect web-config


    【解决方案1】:

    您的第一条规则上的 ? 符号有问题,因为它是一个 Wildcard 字符。

    尝试将appendQueryString="false" 添加到您的第二条规则中:

    <rule name="Redirect" stopProcessing="true">
        <match url="controller/action$" />
        <conditions>  
            <add input="{QUERY_STRING}" pattern="parameter=value" />  
        </conditions> 
        <action type="Redirect" url="controller/action?parameter=anotherValue" redirectType="Permanent" appendQueryString="false" />
    </rule>
    

    【讨论】:

    • 感谢您的建议,但仍然没有。同样的行为。
    • 我刚刚在本地 IIS 上尝试过,它确实有效。请注意,我修改了答案并删除了多余的patternSyntax="Wildcard"
    • 我删除了patternSyntax="Wildcard",它成功了...谢谢!
    猜你喜欢
    • 2018-08-19
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2015-09-23
    相关资源
    最近更新 更多