【问题标题】:Pass Parameters using <httpRedirect> in ASP.Net在 ASP.Net 中使用 <httpRedirect> 传递参数
【发布时间】:2013-01-05 09:06:08
【问题描述】:

在我的 ASP.Net 网站中,我在 Web 配置中使用 &lt;httpRedirect&gt; 将 URL 永久重定向到其他位置。
我正在从表中读取 URL 值并使用 Response.Redirect( URL );
重定向到该 URL 它工作完美。
但是现在当我尝试使用以下方式将参数发送到调用页面时:

Response.Redirect("Default.aspx?name=stackoverflow");

web.config 中的&lt;httpRedirect&gt; 调用Default2.aspx 因为web.config 中有以下代码:

<location path="Default.aspx">
    <system.webServer>
        <httpRedirect enabled="true" destination="Default2.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
</location>

问题是Default2.aspx 没有收到任何参数。
请帮忙。

注意:我不能使用会话变量,因为页面内容取决于该参数。

例如,
如果用户在新选项卡中打开另一个页面,Default.aspx?name=MetaStackOverflow 会话变量将被替换,并且如果第一页被刷新,那么它将显示Stackoverflow 内容而不是显示MetaStackOverflow

【问题讨论】:

    标签: asp.net web-config parameter-passing http-redirect


    【解决方案1】:

    不要忘记特殊字符 $V$Q,exactDestination 必须设置为 True。

    <location path="Help"> <system.webServer> <httpRedirect enabled="true" destination="/Redirect.aspx$V$Q" httpResponseStatus="Permanent" exactDestination="true" /> </system.webServer> </location>

    【讨论】:

    • 它现在正在发送 URL 参数,但是页面被调用了 3 到 4 次,并且我在 Default2.aspx 上的 css 没有应用。这些特殊字符“$V$Q”表示什么?
    • @user1808827:$V 用于 URL 路径,$Q 用于 QueryString。您可以使用`destination="/Redirect.aspx$Q"` 仅传递查询字符串
    • 您是否有列出所有这些关键字/变量的网络资源,例如 $V$Q
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多