Response.Redirect() 不起作用 .net 4.0

发布于 2024-12-11 02:04:36 字数 1999 浏览 0 评论 0原文

在按钮上单击我正在调用 JavaScript 函数,在 JS 函数中我重定向到一个 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 没有重新定位指导,只需发回到当前页面。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2024-12-18 02:04:36

据我所知,您没有采取任何措施来结束请求。我不是 ASP.NET 人员,但我认为您应该:

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

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
独行侠 2024-12-18 02:04:36

与 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:如果使用,则会发生 ThreadAbortException Response.End、Response.Redirect 或 Server.Transfer

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文