ASP.Net 中的 response.redirect 问题
我正在使用 ASP.Net + VSTS 2008 + .Net 3.5 + C# + IIS 7。我想知道如果在服务器端,我调用response.redirect到同一Web应用程序中的另一个Url,会话是否会继续或终止?
例如,如果我在a.aspx中将会话变量foo设置为值“goo”,那么在a.aspx中我调用response.redirect到b.aspx,无论是在b.aspx中我都可以100%获得会话变量foo的值“粘性物”?我的困惑是我听说 response.redirect 不会 100% 继续会话,是真的吗?
提前致谢, 乔治
I am using ASP.Net + VSTS 2008 + .Net 3.5 + C# + IIS 7. I am wondering if at server side, I call response.redirect to another Url in the same web application, whether session will be continued or terminated?
e.g. if I set session variable foo to value "goo" in a.aspx, then in a.aspx I call response.redirect to b.aspx, whether in b.aspx I can 100% get the value for session variable foo to be "goo"? My confusion is I heard response.redirect will not 100% continue session, is that true?
thanks in advance,
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用也采用
bool
的 Response.Redirect 重载,这不会结束响应。Bertrand le Roy 介绍了它 此处。
You can use the overload for Response.Redirect that takes a
bool
as well, which does not end the response.Bertrand le Roy covers it here.
Response.Redirect 将终止您的会话,因此它不一定在
b.aspx
中可用。相反,请尝试使用 Response.Redirect("/b.aspx", false); 其中 false 参数确保响应不会立即终止。Response.Redirect will kill your session and so it won't necessarily be available in
b.aspx
. Instead, try usingResponse.Redirect("/b.aspx", false);
where the false parameter makes sure that the response is not immediately killed.会话值在会话的整个生命周期中保持不变。会话将在浏览器关闭或超时到期或显式关闭后结束。
http://msdn.microsoft.com/en -us/library/ms178581%28v=VS.90%29.aspx
Session values are persisted through the life of the session. The session will end after the browser closes or the timeout expires, or explicitly closed.
http://msdn.microsoft.com/en-us/library/ms178581%28v=VS.90%29.aspx
我的问题如下:-
问题:当我们将 ASP.NET 应用程序移动到另一台具有 IIS 7.5 的服务器 (Windows Server 2008 R2) 时,应用程序无法在页面之间移动会话值。例如,会话值已在第一页中设置,但无法移动到下一页。在下一页中,同一会话变量的值变为 NULL。
在 Google Chrome 和 Firefox 中,会话值移至下一页,但在 Internet Explorer 中则不然。
解决方案:我们创建了带有“_”(下划线)的 URL 名称
其他可能的解决方案:
使用 Response.Redirect 并将第二个参数设置为“false”以避免执行页面,从而避免丢失会话令牌。您必须使用如下 URL。 Response.Redirect("NextPage.aspx",false)
如果站点的应用程序池配置为网络场或网络花园(通过将最大工作进程数设置为多个),并且如果您如果不使用会话服务或 SQL 会话,传入请求将不可预测地转到其中一个工作进程,如果该进程不是创建会话的进程,则该会话就会丢失。此问题的解决方案是,如果不需要性能提升,则不要使用网络花园,或者使用进程外会话提供程序之一。
My problem was as follows :-
Problem: When we have moved the ASP.NET application to an another server (Windows Server 2008 R2) with IIS 7.5, the application cannot move session values between the pages. e.g. the session value was set in first page but it could not move to next page. In next page, value for same session variable was coming NULL.
Session values was moving to next page in case of Google Chrome and Firefox but not in Internet Explorer.
Resolution: We have created URL name with "_" (underscore)
Other Possible Solution:
Use Response.Redirect with having second parameter as "false" to avoid execution of page and thus to avoid lose session token. You have to use URL as follows. Response.Redirect("NextPage.aspx",false)
If the application pool of the site is configured as a web farm or a web garden (by setting the maximum number of worker processes to more than one), and if you're not using the session service or SQL sessions, incoming requests will unpredictably go to one of the worker processes, and if it's not the one the session was created on, it's lost. The solutions to this problem is either not to use a web garden if you don't need the performance boost, or use one of the out of process session providers.
如果 url 是绝对 url(如果您不想失去会话使用),Response.Redirect(url,false) 函数将更改会话改为绝对路径。
The Response.Redirect(url,false) function will change the session if the url was absolute url if you dont want to loose the session use absolute path instead .