簡體   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