繁体   English   中英

.NET 4.0的Response.Redirect()不起作用

[英]Response.Redirect() doesn't work .net 4.0

在按钮上单击我在JS函数中调用javascript函数,将我重定向到一个aspx页面,在aspx页面中,我想重定向到另一个页面(这部分不起作用)。 response.redirect不会重新定向,只是回发到当前页面。 任何想法为什么它不工作。

这是我的代码:

Review.aspx:

<asp:Button ID="btnComplt" runat="server" Text="Complete" OnClientClick ="return compAsgn()" />

function compAsgn() {
       if (window.confirm("Submit all images and complete the assignment?"))
           window.location = "SendImages.aspx?insid=" + $("#IAssignmentId").val() + '&option=complete';
       else
           return false;

SendImages.aspx:

 protected void Page_Load(object sender, EventArgs e)
        {
            assignmentId = Convert.ToInt32(Request.QueryString["insid"]);
            string url = "Review.aspx?insid" + assignmentId.ToString() + "&viewOption=review";

            string qstrVal = string.Empty;
            qstrVal = Request.QueryString["option"].ToString().ToLower();
            if (qstrVal != null && qstrVal == "complete")
            {
                using (ServiceClient client = new Proxies.ServiceRef.ServiceClient())
                {
                    List<AssignmentInfo> ainfo = new List<AssignmentInfo>();
                    ainfo = client.GetAssignmentInfo(assignmentId);
                    if (ainfo.Count > 0)
                    {
                        if (ainfo[0].UploadedCount == 0)
                        {
// AfarSessionData class has a property called ProfileId, which is session variable.  
                            if (AfarSessionData.ProfileId == "000000")
                                url = "Admin.aspx";
                            else
                                url = "HomePage.aspx";
                        }


                    }
                }

            }


            Response.Redirect(url, false);
        }

注意:当我调试时,我确实看到控件点击SendImages页面,但我看到response.redirect没有重定向,只是回发到当前页面。

据我所知,你没有做任何事情来结束请求。 我不是ASP.NET专家,但我认为您应该:

  • 使第二个参数成为true有效“硬中止”请求的异常
  • 使第二个参数为false ,但随后调用CompleteRequest以停止管道的其余部分

与John Skeets相关的一些其他信息回答:

//ends request, no exception, calls Response.End() internally
Response.Redirect (url, true);

要么

try
{
    Response.Redirect (url, false);
}
catch(ThreadAbortException e)
{
    //do whatever you need to
}

以下是有关此问题的一些信息:

PRB:如果您使用Response.End,Response.Redirect或Server.Transfer,则会发生ThreadAbortException

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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