简体   繁体   中英

Asp.net Response.Redirect Error

My team and I are working on a portal applicaiton. When a user requests a page, we get a page object (contianing permissions, actual file to use and what not). We then do a Response.Redirect to "~/Default.aspx".

The crazy thing is that when the code to validate access and what not is called from a button click event from within an ajax update panel, response.redirect is pasting a "&f2" or a "/" into the url. So rather than http://localhost/Default.aspx , the webbrowser is being redirected to http://localhost/%f2Default.aspx , and is subsequently returning a 404 error.

HttpContext.Current.Response.Redirect("~/Default.aspx", false);

Anyone have an idea of why this would occur? And it only happens when the click event fires inside an update panel.

It sounds like it is escaping the URL. Can you call a method on the code that is generating the URL to decode it before output?

The solution is to set up the update panel like this:

<asp:UpdatePanel ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddlNewAddressCountry" EventName="SelectedIndexChanged" />
    <asp:AsyncPostBackTrigger ControlID="ddlAddressState" EventName="SelectedIndexChanged" />
    <asp:AsyncPostBackTrigger ControlID="ddlNewAddressCity" EventName="SelectedIndexChanged" />
    <asp:AsyncPostBackTrigger ControlID="ddlNewAddressPostalCode" EventName="SelectedIndexChanged" />
    <asp:PostBackTrigger ControlID="btnCustomerAddressEditCancel" />
  </Triggers>
...
 <td colspan="2">
                            <asp:Button ID="btnCustomerAddressEditSave" runat="server" OnClick="CustomerAddressEditSave_Click"
                                Text="Save" />
                            &nbsp;&nbsp;&nbsp;
                           <asp:Button ID="btnCustomerAddressEditCancel" runat="server" CausesValidation="false" OnClick="CustomerAddressEditCancel_Click"
                                Text="Cancel" />
                            &nbsp;&nbsp;&nbsp;
                            <asp:Button ID="btnCustomerAddressEditDelete" runat="server" OnClick="CustomerAddressEditDelete_Click" OnClientClick="return confirm('Are you sure you want to delete this record?');"
                                Text="Delete" />
                        </td>
                    </tr>
                </table>
        </ContentTemplate>
    </asp:UpdatePanel> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM