简体   繁体   中英

Response.Redirect() doesn't work .net 4.0

On the button click I am calling a javascript function in the JS function I redirect to an aspx page and in the aspx page I want to redirect to another page (This part is not working). response.redirect not re-directing, just posting back to current page. Any Idea why it is not working.

Here is my code :

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);
        }

Note : When I debug I do see the control hitting the SendImages page but I see response.redirect not re-directing, just posting back to current page.

As far as I can tell, you're not doing anything to end the request. I'm not an ASP.NET guy, but I thought you should either:

  • Make the second argument true to effectively "hard abort" the request with an exception
  • Make the second argument false , but then call CompleteRequest to stop the rest of the pipeline

Some additional info related to John Skeets answer:

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

or

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

Here is some info on the issue:

PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

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