[英]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). 在按钮上单击我在JS函数中调用javascript函数,将我重定向到一个aspx页面,在aspx页面中,我想重定向到另一个页面(这部分不起作用)。 response.redirect not re-directing, just posting back to current page.
response.redirect不会重新定向,只是回发到当前页面。 Any Idea why it is not working.
任何想法为什么它不工作。
Here is my code : 这是我的代码:
Review.aspx: 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 : 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. 注意:当我调试时,我确实看到控件点击SendImages页面,但我看到response.redirect没有重定向,只是回发到当前页面。
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:
我不是ASP.NET专家,但我认为您应该:
true
to effectively "hard abort" the request with an exception true
有效“硬中止”请求的异常 false
, but then call CompleteRequest
to stop the rest of the pipeline false
,但随后调用CompleteRequest
以停止管道的其余部分 Some additional info related to John Skeets answer: 与John Skeets相关的一些其他信息回答:
//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 PRB:如果您使用Response.End,Response.Redirect或Server.Transfer,则会发生ThreadAbortException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.