使用respnse.redirect("page",true) [英] Use of respnse.redirect("page",true)

查看:89
本文介绍了使用respnse.redirect("page",true)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


请确认我什么是response.redirect第二个参数true和false

response.redirect("page.aspx",true);

Hi,
Please confirm me what is use of response.redirect second parameter true and false
ex
response.redirect("page.aspx",true);
what is work of true

推荐答案

的工作原理是什么?如果将第二个参数写为true,它将抛出异常

System.Threading.ThreadAbortException:线程正在中止.

因为正在运行的线程已结束并正在尝试另一个线程.
并且如果您写入false,它将不会显示任何异常.

Response.Redirect("page_name.aspx",true)<-引发异常.
Response.Redirect("page_name.aspx",false)<-Exception Free.

这些链接可能对您有帮助
ThreadAbortException [ http://support.microsoft.com/kb/312629 [
If you write the second parameter as true than it will throw an exception
i.e.
System.Threading.ThreadAbortException: Thread was being aborted.

because the running thread is ended and trying for another thread.
and if you write false than it will not show any exception.

Response.Redirect("page_name.aspx",true)<--Throw Exception.
Response.Redirect("page_name.aspx",false)<--Exception Free.

These links may help you
ThreadAbortException[^]
http://support.microsoft.com/kb/312629[^]


http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.80%29.aspx [ ^ ]
http://blogs.msdn.com/b/jongallant/archive/2006/06/20/640484.aspx [ ^ ]
http://dotnetgems.blogspot.in/2008/12/what-is-responseredirecturlbollean.html [^ ]
http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.80%29.aspx[^]
http://blogs.msdn.com/b/jongallant/archive/2006/06/20/640484.aspx[^]
http://dotnetgems.blogspot.in/2008/12/what-is-responseredirecturlbollean.html[^]


Response.Redirect的第二个参数是endResponse(请参见此函数的工具提示),它是一个布尔值,指示是否停止运行当前页面.
这取决于您要保留它还是保留它.

当您不想中止线程时使用"false",即false将导致代码继续执行.因此,将执行在 Response.Redirect 之后出现的代码行. "true"将杀死线程,因此将不再执行任何操作,这又将引发ThreadAbortException.

因此,这实际上取决于在这种情况下必须如何执行其余代码.通常,您希望在执行路径的末尾放置对 Response.Redirect 的调用,以便不再需要执行任何操作.但是很多时候情况并非如此.只是如何控制代码中的逻辑流程.
The second parameter of Response.Redirect is endResponse(see in tooltip of this function) which is boolean value that indicates whether to stop running the current page.

It depends on if you want to keep it alive or stop it.

Use "false" when you don''t want to abort the thread i.e. false will cause the code to continue to execute. So lines of code which appear after the Response.Redirect will be executed. A "true" will just kill the thread so nothing further will execute, which in turn throws a ThreadAbortException.

So it''s really based on how the rest of the code in that situation has to be executed. Generally you want to put calls to Response.Redirect at the end of an execution path so that nothing further needs to be executed. But many times that''s not the case. It''s just a matter of how you control the logic flow in the code.


这篇关于使用respnse.redirect("page",true)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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