Response.Redirect不结束执行 [英] Response.Redirect not ending execution

查看:120
本文介绍了Response.Redirect不结束执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Default.aspx页面,该页面继承自BasePage.cs,而BasePage.cs继承自System.Web.UI.Page.我在BasePage上做了一些常见的事情,每个页面在加载时都必须做.

I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is where I do some common things every page must do upon loading.

在BasePage中,可以说我正在检查X.如果X = 1,那么我将立即重定向到我的"Discontinued.aspx"页面,并停止执行BasePage.如果我发现X = 1,我会说:

In BasePage, lets say I'm checking for X. If X=1, then I will redirect to my "Discontinued.aspx" page immediately and stop execution of BasePage. If I find X=1, I say:

HttpContext.Current.Response.Redirect("Discontinued.aspx",true);

HttpContext.Current.Response.Redirect("Discontinued.aspx", true);

我希望重定向停止BasePage的执行并立即跳出-因此上述语句中的"true"-据我所知,这应该停止当前页面的执行.问题是,事实并非如此.我期望重定向抛出线程异常中止".

I want the redirect to stop execution of BasePage and immediately jump out - hence the "true" in the above statement - which should stop execution of the current page as I understand. The problem is, it doesn't. I'm expecting the redirect to throw the "thread abort exception".

当我在调试模式下运行时,它会继续逐步执行,就好像它不仅仅是重定向并离开一样.

When I run in debug mode, it contines stepping through as though it didn't just redirect and leave.

但是,重定向还是同样开始的-一旦我完成了对BasePage其余部分的逐步浏览,然后就由于重定向而开始加载已终止"页面.

But the redirect was still started as well - once I get done stepping through the rest of BasePage, the "Discontinued" page then begins to load as a result of the redirect.

我的重定向是否有理由不会终止BasePage的执行?

Is there a reason my Redirect will not kill execution of BasePage?

推荐答案

您是否要退出调用重定向的功能,例如

are you exiting from the function that calls redirect, e.g.

...redirect(stopit,true);
return;

?

这篇关于Response.Redirect不结束执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆