ASP.NET 相当于 JSF 会话 Bean
我对 JSF 和 ASP.NET 都很陌生,据我所知(如果我错了,请纠正我),在 JSF 中使用会话作用域 bean 时,数据临时存储在服务器端,供组件使用。但在 ASP.NET 中,此类临时数据似乎存储在页面本身的隐藏字段中,称为 Viewstate。
我的假设正确吗? ASP.NET 中是否有任何东西可以自动管理数据并将其存储在服务器端的对象中(就像 JSF 那样)?
I'm fairly new to both JSF and ASP.NET, and as far as I can understand (correct me if I'm wrong), while using session scoped beans in JSF, data is stored on the server side temporarily, for the components. But in ASP.NET it seems that such temporary data is stored in a hidden field in the page itself, called Viewstate.
Am I right in assuming this? Is there anything in ASP.NET that'll automatically manage the data and store it server side in objects (like JSF does) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 支持视图状态和会话状态。这是有关会话状态的一些信息的链接。
http://msdn.microsoft.com/en-us/library/ms178581.aspx
我建议您尽量避免使用视图状态,并谨慎使用会话状态。您应该努力使 ASP.NET 应用程序尽可能保持“无状态”。不要过度使用会话状态,否则您可能会遇到可扩展性问题。考虑以下替代方案。
https://web.archive.org/web/20211020145945/https://www.4guysfromrolla.com/webtech/041600-2.shtml
ASP.NET has support for both a Viewstate and a Session state. Here is a link to some info regarding session state.
http://msdn.microsoft.com/en-us/library/ms178581.aspx
I'd recommend that you try to avoid using the viewstate at all, and use the session state sparingly. You should strive to keep your ASP.NET applications as "stateless" as possible. Do not over-use the session state or you could experience scalability issues down the road. Consider the following alternatives.
https://web.archive.org/web/20211020145945/https://www.4guysfromrolla.com/webtech/041600-2.shtml
您可以使用 ASP.NET 会话状态。
数据实际存储的位置(内存中、数据库中)是可以配置的。根据您的情况,将状态存储在视图中可能会更好。在单个用户可能同时打开两个浏览器窗口并希望它们保持单独状态(例如向导工作流中的当前阶段)的任何情况下,使用视图状态会更好。
You can use ASP.NET Session State.
Where the data is actually stored (in memory, in a database) can be configured. Depending on your situation, it may be better to store state in the view. Using the view state would be better in any situation where a single user might have two browser windows open at the same time, and expect them to keep separate state, such as the current stage in a wizard workflow.