为什么FormsAuthentication.RedirectFromLoginPage()以context.Response.Redirect(...,false)结尾?

时间:2010-01-10 21:54:41

标签: .net asp.net asp.net-mvc forms-authentication

我浏览了FormsAuthentication的源代码,发现它以

结尾
context.Response.Redirect(strUrl, false);

'false'参数代表“不要终止当前页面的执行”。

为什么不调用FormsAuthentication.RedirectFromLoginPage()需要终止查看当前页面?调用此方法后的正确行为是什么?

1 个答案:

答案 0 :(得分:4)

将“endResponse”设置为true表示Response.Redirect()调用也会强制拨打Response.End()

Response.End()会立即将代码执行转移到Application_EndResponse事件,并在所有内容结束时引发ThreadAbortException

基本上,如果将参数保留为false,则会更清楚地“关闭”响应。如果您可以在Response.Redirect()调用之后立即将方法的逻辑结构化为基本完成,则可以避免强制执行Response.End()时发生的所有奇怪事情。

相关问题