I have a button in an UpdatePanel that if it is clicked will redirect the user to another page in the same folder in some cases and otherwise will update the UpdatePanel with some info. If I do a redirect in this way:
Response.Redirect("Test.aspx");
it does a redirect to /Test.aspx which in most cases would be fine, but the problem is that the application is accessed through a reverse proxy (at x.com/y/) which will cause some problem since /Test.aspx will redirect the user to a nonexisting file in the root of the server that does the proxying.
Is it possible to force the redirect to skip the / stuff since it is not necessary in this case, since both files are in the same folder.
Edit: Code sample
<asp:ScriptManager ID="script" runat="server" />
<asp:UpdateProgress ID="prog" runat="server" AssociatedUpdatePanelID="up">
<ProgressTemplate>
<h1>Waiting...</h1>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:TextBox ID="txt" runat="server" />
<asp:Button ID="btn" runat="server" OnClick="click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
Click method:
protected void click(object sender, EventArgs e)
{
Thread.Sleep(3000);
if (txt.Text == "redirect")
Response.Redirect("Test.aspx");
else
txt.Text = "";
}
Did you give a try for redirecting to a relative path? Something like below?
Response.Redirect("~/Test.aspx")
Please give the correct relative path where the Test.aspx resides. Hope this helps.
You can't redirect in an async postback. Add the button as a PostBackTrigger
:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
The other solution is to add the following script module to your web.config
:
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
in your ajax callback handler you should check 301 status code and redirect like below
response = ajaxContext.get_response();
if (response.get_statusCode() == 301)
window.location = response.getResponseHeader('Location');
来源:https://stackoverflow.com/questions/8078641/response-redirect-in-asp-net-ajax-calls