【问题标题】:Response.Redirect is improperly URL-encoding the destination URLResponse.Redirect 对目标 URL 的 URL 编码不正确
【发布时间】:2014-05-28 20:38:09
【问题描述】:

在一个旧的 VB.NET 网站中,管理部分中有一个页面,其 URL 类似于 http://example.com/Admin/EditUser.aspx。在该页面上提交按钮的事件处理程序结束时,它尝试使用添加的查询字符串重定向到自身,如下所示:Response.Redirect("EditUser.aspx?a=b")。这会导致我的浏览器尝试重定向到http://example.com/Admin/%2fAdmin%2fEditUser.aspx%3fa%3db,这是错误的。如果我将 ~/ 添加到 Response.Redirect 调用中,它会重定向到 http://example.com/Admin/%2fEditUser.aspx%3fa%3db,这仍然是错误的。即使我从重定向 URL 中删除查询字符串,Response.Redirect 仍然会添加一个多余的%2f。

这是什么原因造成的,我该如何解决?

编辑:这个人有同样的问题,并得出结论这是 .NET 4.0 中的一个错误:Response.redirect puts extra characters in the url Error 400

他的解决方法是在 Javascript 中使用 document.location。但我仍然想知道如何在服务器端解决这个问题。

【问题讨论】:

标签: asp.net vb.net response.redirect


【解决方案1】:

这原来是 Response.Redirect 中的一个错误,它是由 UpdatePanel 中包含的提交按钮引起的。解决方案是将<Triggers> 部分添加到UpdatePanel,如下所示:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
        <asp:PostBackTrigger ControlID="btnSubmit" />  
    </Triggers>
    <ContentTemplate>
        <%-- ...Content goes here... --%>
        <asp:Button runat="server" ID="btnSubmit"/>
    </ContentTemplate>
</asp:UpdatePanel>

这让我发疯了,所以我希望它对某人有所帮助。

【讨论】:

    猜你喜欢
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2018-09-20
    • 1970-01-01
    • 2021-07-28
    相关资源
    最近更新 更多