如何使aspx页面执行httpredirect?

如何使aspx页面执行httpredirect?,redirect,web-config,Redirect,Web Config,我正在尝试将一个aspx页面重定向到另一个aspx页面。但是,只有在调用aspx页面时才使用,没有任何参数 所以当它这样叫的时候:它不需要做任何事情。 但当它被这样调用时:它必须重定向 我试过了,但它没有重定向,而是执行aspx <system.webServer> <httpRedirect enabled="true" httpResponseStatus="Found" exactDestination="true"> <add wildca

我正在尝试将一个aspx页面重定向到另一个aspx页面。但是,只有在调用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>

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


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

thx有关想法,我最终将其放在aspx文件的Onprerender方法中。Prerender在页面生命周期中较晚。如果您想在重定向之前优化加载时间,我建议您在页面PreInit或Init中进行重定向(查看页面了解更多信息,该图非常有用)。