1

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 = "";
}
Nocklas
  • 1,367
  • 4
  • 15
  • 27

3 Answers3

0

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');
Iman
  • 17,932
  • 6
  • 80
  • 90
0

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.

clklachu
  • 951
  • 1
  • 7
  • 19
  • "~/Test.aspx" and "Test.aspx" result in the same response when I look at the post in Bugzilla ( 1|#||4|12|pageRedirect||%2fTest.aspx|). – Nocklas Nov 10 '11 at 16:39
0

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>
James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • Yes, it is possible. It doesn't create a 302 or something like that, but the response from the post looks like this in bugzilla "1|#||4|12|pageRedirect||%2fTest.aspx|" and I guess this is the used by some autogenerated javascript or something to redirect the page. – Nocklas Nov 10 '11 at 16:36
  • @Nocklas: No, you get an exception when trying to redirect during an async postback. – James Johnson Nov 10 '11 at 16:40
  • What is the problem with providing a relative path to the file? Seems like the easiest solution, and the most scalable one as well. – James Johnson Nov 10 '11 at 17:01
  • Since this code will be hosted at b.com and also accessed through a reverse proxy at a.com/b/ links like /Test.aspx becomes a problem when accessing it through the reverse proxy. It would be nice if the reverse proxy didn't have to have special rules to handle stuff like this. – Nocklas Nov 10 '11 at 17:37