如何让aspx页面做一个httpredirect?

时间:2013-09-24 11:27:49

标签: redirect web-config

我正在尝试将aspx页面重定向到另一个aspx页面。但只有在没有任何参数的情况下调用aspx页面。

所以,当这样调用时:https://www.a.com/test.aspx?param=1它不需要做任何事情。 但是当它被调用时:https://www.a.com/test.aspx它必须重定向。

我尝试了这个,但它不重定向,而是执行aspx。

<system.webServer>
   <httpRedirect enabled="true" httpResponseStatus="Found" exactDestination="true">
      <add wildcard="*test.aspx" destination="/destination.aspx"/>
    </httpRedirect>
</system.webserver>

有什么想法吗?

额外信息:来自https域。

我也尝试过以下操作,但这会让它崩溃:

<rewrite>
    <rules>
        <rule name="myrule" stopProcessing="true">
            <match url="/test.aspx" />
            <action
                type="Redirect"
                url="/destination.aspx"
                appendQueryString="false"
                redirectType="Found" />
        </rule>
    </rules>
</rewrite>

1 个答案:

答案 0 :(得分:1)

一种方法是在ASPX页面的页面加载中使用代码。如果没有提供查询字符串,那么请进行重定向。

如果您想更早地进行重定向,您还可以使用global.asax BeginRequest事件重定向(检查当前请求的URI并在需要时重定向)。