在的Response.Redirect ASP.NET AJAX调用 [英] Response.Redirect in ASP.NET AJAX calls

查看:173
本文介绍了在的Response.Redirect ASP.NET AJAX调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个UpdatePanel一个按钮,如果它被点击将用户重定向到相同的文件夹在一些情况下的另一页和否则将更新的UpdatePanel一些信息。如果我做一个重定向以这种方式:

 的Response.Redirect(Test.aspx的);
 

它重定向到/Test.aspx在大多数情况下会被罚款,但问题是,应用程序是通过反向代理(在x.com/y/),这将导致,因为一些问题访问/测试的.aspx将用户重定向到一个不存在的文件,做了代理服务器的根目录。

是否有可能以强制重定向跳过/东西,因为它没有必要在此情况下,由于两个文件都在相同的文件夹。

编辑:code样品

 < ASP:ScriptManager的ID =脚本=服务器/>
< ASP:的UpdateProgress ID =前卫=服务器AssociatedUpdatePanelID =上升与GT;
   < ProgressTemplate>
      < H1>等待...< / H1>
   < / ProgressTemplate>
< / ASP:的UpdateProgress>
< ASP:UpdatePanel的ID =向上=服务器的UpdateMode =条件ChildrenAsTriggers =真正的>
   <的ContentTemplate>
       < ASP:文本框ID =TXT=服务器/>
           < ASP:按钮的ID =BTN=服务器的OnClick =点击文本=按钮/>
    < /的ContentTemplate>
< / ASP:UpdatePanel的>
 

点击方式:

 保护无效点击(对象发件人,EventArgs的)
{
  Thread.sleep代码(3000);
  如果(txt.Text ==重定向)
     的Response.Redirect(Test.aspx的);
  其他
     txt.Text =;
}
 

解决方案

您不能重定向在异步回发。添加该按钮为 PostBackTrigger

 < ASP:UpdatePanel的ID =UpdatePanel1=服务器>
    <触发器>
        < ASP:PostBackTrigger控件ID =Button1的/>
    < /触发器>
    <的ContentTemplate>

    < /的ContentTemplate>
< / ASP:UpdatePanel的>
 

另一个解决方案是将下面的脚本模块添加到您的的web.config

 <的HttpModules>
    <添加名称=ScriptModuleTYPE =System.Web.Handlers.ScriptModule,System.Web.Extensions程序,版本= 1.0.61025.0,文化=中性公钥= 31bf3856ad364e35/>
< / HttpModules的>
 

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 = "";
}

解决方案

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>

这篇关于在的Response.Redirect ASP.NET AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆