简体   繁体   English

无状态asp.net应用程序和ViewState

[英]Stateless asp.net application and ViewState

Microsoft document http://www.asp.net/aspnet/overview/developing-apps-with-windows-azure/building-real-world-cloud-apps-with-windows-azure/web-development-best-practices encourages to keep web application stateless, however mentions also that real-world applications need to store data and it is suggested to Microsoft文档http://www.asp.net/aspnet/overview/developing-apps-with-windows-azure/building-real-world-cloud-apps-with-windows-azure/web-development-best-practices鼓励为了使Web应用程序保持无状态,但是还提到现实世界中的应用程序需要存储数据,因此建议

"not to store it on the web server. You can store state in other ways, such as on the client in cookies or out of process server-side in ASP.NET session state using a cache provide". “不要将其存储在Web服务器上。您可以通过其他方式存储状态,例如使用cookie提供在cookie上的客户端上或ASP.NET会话状态下的不在进程服务器端的状态”。

Following this logic, is using ViewState in ASP.Net Web Forms application stateful of stateless approach? 遵循此逻辑,是否在ASP.Net Web Forms应用程序中使用ViewState声明了无状态方法? It is kept at client side, same as mentioned cookies. 它与提到的cookie一样保存在客户端。 Let's assume ideal scenario where I do not use any Session and Application to store data. 让我们假设理想的情况是我不使用任何会话和应用程序来存储数据。

Sure; 当然; using ViewState is just like using cookies in terms of statelessness. 就无状态而言,使用ViewState就像使用cookie。

Be aware that Web Forms are an out-dated technology that MS and the development community has moved away from. 请注意,Web窗体是MS和开发社区已淘汰的过时技术。 You should look in Razor templating which a much more lightweight and flexible approach to rendering asp.net web applications. 您应该查看Razor模板,该模板是呈现ASP.NET Web应用程序的一种更轻量级,更灵活的方法。

Bloat is a big problem with the amount of data saved in ViewState, While this is probably OK if you are creating an departmental CRUD application, it probably won't fly for something targeting mobile devices. Bloat是ViewState中保存的数据量很大的问题,尽管如果创建部门CRUD应用程序可能没问题,但它可能不适用于针对移动设备的应用程序。

Also, Web Forms produce very idiosyncratic HTML which makes it difficult to use modern client side technologies. 而且,Web窗体会生成非常特殊的HTML,这使得使用现代客户端技术变得困难。

Here's a link to a pretty good article on the ascent of razor templating and the decline of web forms. 这是一篇不错的文章的链接,内容涉及剃须刀模板的兴起和网络表单的减少。

The term "ViewState" has "state" in it, therefore it is by definition considered to provide the state of the view. 术语“ ViewState”中具有“状态”,因此根据定义,它被视为提供视图的状态。 Unlike cookies, however, ViewState provides state for only the view, not any other page or session. 但是,与cookie不同,ViewState仅提供视图的状态,而不提供其他任何页面或会话的状态。 Cookies can be used in future sessions, ViewState only in the current instance of the view. Cookies可以在以后的会话中使用,ViewState只能在视图的当前实例中使用。 To the extent that ViewState is lost when the page is gone, ViewState is not kept client-side. 如果页面消失时ViewState丢失,则ViewState 不会保留在客户端。 The primary purpose of ViewState is to preserve the state across post-backs, not for use anywhere else outside of the page. ViewState的主要目的是在回发之间保留状态,而不是在页面之外的其他任何地方使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM