在Response.Redirect中使用endResponse [英] Using endResponse in a Response.Redirect

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

问题描述

在ASP.NET页中执行response.redirect时,我收到了错误消息:
错误:无法获取价值
传入的两个变量(一个值是从查询字符串中检索的,另一个是从viewstate中检索的)

我之前从未见过此错误,因此我进行了一些调查,找到了建议对"endResponse"使用"False"值

例如Response.Redirect("mypage.aspx",False)

这行得通.

我的问题是:在response.redirect中为"endResponse"值使用"False"有什么副作用?
即对服务器的缓存有影响吗?页面是否在内存中保留一段时间?这会影响不同用户查看同一页面吗?等等.

谢谢!

While performing a response.redirect in an ASP.NET page, I received the error:
error: cannot obtain value
for two of the variables being passed in (one value being retrieved from the querystring, the other from viewstate)

I've never seen this error before, so I did some investigating and found recommendations to use the "False" value for "endResponse"

e.g. Response.Redirect("mypage.aspx", False)

This worked.

My question is: what are the side-effects of using "False" for the "endResponse" value in a response.redirect?
i.e. are there any effects on the server's cache? Does the page remain resident in memory for a period? Will it affect different users viewing the same page? etc.

Thanks!

推荐答案

来自其他问题此博客帖子,推荐的模式是-

From this other question and this blog post, the recommended pattern is-

Response.Redirect(url, false);
Context.ApplicationInstance.CompleteRequest();

这避免了昂贵的ThreadAbortException/Response.End.在 CompleteRequest()之后将执行一些代码,但是ASP.Net将在方便时立即关闭请求.

This avoids the expensive ThreadAbortException/Response.End. Some code will be executed after the CompleteRequest(), but ASP.Net will close the request as soon as it is convenient.

编辑-我认为此答案提供了最佳概述.请注意,如果您使用上述模式,则重定向后的代码仍将执行.

Edit- I think this answer gives the best overview. Note that if you use the pattern above, code after the redirect will still be executed.

这篇关于在Response.Redirect中使用endResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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