如何学习 ASP.NET 状态管理的最佳实践
我是编程新手,特别是网络编程新手。我想学习有关状态管理技术的最佳实践。我的意思是
我们什么时候必须创建会话?
什么时候使用会话如何检查空会话? 、
什么时候使用cookies?
何时使用隐藏字段?
两者之间有什么区别?
在特定时间使用哪种技术?
应用程序如何可能因状态管理不成功而崩溃?。 当我们开发Web应用程序时,我们需要记住哪些关于状态管理的事情......???
有很多问题。也许你们知道。请帮我解决我的困惑。
提前致谢 !
I am new in programming ,specially in web base programming. i want to learn best practices about state management techniques. I mean
when we have to create sessions?,
when to use sessions how to check null sessions? ,
when to use cookies ?
when to use hidden fields ?.
what are differences between all ?
which technique to use at certain time ?
how application may get crashes due to unsuccessful state management?.
which things we need to keep in mind about state management when we are developing the web applications...???
there so many questions . perhaps you guys known . please help me out to sort my confusion .
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你只需要阅读一些书就可以了。
Pro ASP.NET - 这本书有一章是关于状态管理的,但是我我打赌本书的其余部分也会对您有所帮助,因为您是初学者。
另外,MSDN 有一些关于状态管理和何时使用的好信息什么。
Sounds like you should just need to do some reading.
Pro ASP.NET - This book has a chapter about state management, but I am betting the rest of the book would be helpful to you as well since you are a beginner.
Also, MSDN has some good information about state management and when to use what.
点击链接:-
状态管理中的客户端-服务器差异:
http://www.techbaba.com/q/858-difference+clint+side+management+server+side+management.aspx
http://www.dotnetfunda.com/articles/article61.aspx
缓存最佳实践:
http://msdn.microsoft.com/en-us/library/aa478965.aspx
状态管理最佳实践:
http://msdn.microsoft.com/en-us/library/ z1hkazw7.aspx
在 C# 中使用状态管理技术:
http:// /www.c-sharpcorner.com/UploadFile/freelance91/ASPNETstatemanagementtechniques01012007212655PM/ASPNETstatemanagementtechniques.aspx
follow the links :-
Client - server difference in state management:
http://www.techbaba.com/q/858-difference+clint+side+management+server+side+management.aspx
http://www.dotnetfunda.com/articles/article61.aspx
Caching best practices :
http://msdn.microsoft.com/en-us/library/aa478965.aspx
state management Best practices :
http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx
Use state management techniques in c# :
http://www.c-sharpcorner.com/UploadFile/freelance91/ASPNETstatemanagementtechniques01012007212655PM/ASPNETstatemanagementtechniques.aspx
http://www.devdescent.com/2012/05/state-management。 html
状态管理是针对相同或不同页面的多个请求维护状态和页面信息的过程。
状态管理的类型
状态管理有两种类型:
它通过将信息嵌入到网页、统一资源定位器 (url) 或 cookie 中来将信息存储在客户端计算机上。 的技术:
下面列出了可用于在客户端存储状态信息 视图状态 – Asp.Net 使用视图状态来跟踪控件中的值。您可以将自定义值添加到视图状态。 Asp.net 页面框架使用它在渲染到页面之前自动保存页面和每个控件的值。发布页面后,页面处理执行的首要任务之一是恢复视图状态。
b.控件状态 – 如果您创建需要视图状态才能正常工作的自定义控件,则应使用控件状态来确保其他开发人员不会通过禁用视图状态来破坏您的控件。
c.隐藏字段 – 与视图状态类似,隐藏字段以 HTML 表单存储数据,而不将其显示在用户的浏览器中。仅当处理表单时数据才可用。
d. Cookie – Cookie 在用户浏览器中存储一个值,浏览器将每个页面请求发送到同一服务器。 Cookie 是存储状态数据的最佳方式,这些数据必须可供网站上的多个网页使用。
e.查询字符串 - 查询字符串存储用户可见的 URL 中的值。当您希望用户能够通过 URL 发送电子邮件或即时消息状态数据时,请使用查询字符串。
管理应用程序状态 - 应用程序状态信息可用于所有页面,无论哪个用户请求页面。
b.会话状态 – 会话状态信息可用于用户在单次访问期间打开的所有页面。
当应用程序重新启动时,应用程序状态和会话状态信息都会丢失。要在应用程序重新启动之间保留用户数据,您可以使用配置文件属性来存储它。
优点
客户端状态管理的优点:
更好的可扩展性:通过服务器端状态管理,每个连接到 Web 服务器的客户端都会消耗 Web 服务器上的内存。如果网站有数百或数千个并发用户,则存储状态管理信息所消耗的内存可能会成为限制因素。将这一负担推给客户可以消除潜在的瓶颈。
支持多个 Web 服务器:通过客户端状态管理,您可以在多个 Web 服务器之间分发传入请求,而无需更改应用程序,因为客户端提供了 Web 服务器处理请求所需的所有信息。使用服务器端状态管理,如果客户端在会话中间切换服务器,则新服务器不一定有权访问客户端的状态信息。您可以使用具有服务器端状态管理的多台服务器,但您需要智能负载平衡(始终将来自客户端的请求转发到同一服务器)或集中式状态管理(其中状态存储在所有 Web 服务器的中央数据库中)访问)。
服务器端状态管理的优点:
更好的安全性:客户端状态管理信息可能被捕获(无论是在传输中还是存储在客户端上)或被恶意修改。因此,您永远不应该使用客户端状态管理来存储机密信息,例如密码、授权级别或身份验证状态。
减少带宽:如果您存储大量状态管理信息,将该信息来回发送到客户端可能会增加带宽利用率和页面加载时间,从而可能增加成本并降低可扩展性。带宽使用量的增加对移动客户端的影响最大,因为它们的连接速度通常非常慢。相反,您应该在服务器上存储大量状态管理数据(例如超过 1 KB)
http://www.devdescent.com/2012/05/state-management.html
State management is the process by which you maintain state and page information over multiple requests for the same or different pages.
Types of State Management
There are 2 types State Management:
This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator(url), or a cookie. The techniques available to store the state information at the client end are listed down below:
a. View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.
b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state.
c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.
d. Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.
e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.
a. Application State - Application State information is available to all pages, regardless of which user requests a page.
b. Session State – Session State information is available to all pages opened by a user during a single visit.
Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.
Advantages
Advantages of Client – Side State Management:
Better Scalability: With server-side state management, each client that connects to the Web server consumes memory on the Web server. If a Web site has hundreds or thousands of simultaneous users, the memory consumed by storing state management information can become a limiting factor. Pushing this burden to the clients removes that potential bottleneck.
Supports multiple Web servers: With client-side state management, you can distribute incoming requests across multiple Web servers with no changes to your application because the client provides all the information the Web server needs to process the request. With server-side state management, if a client switches servers in the middle of the session, the new server does not necessarily have access to the client’s state information. You can use multiple servers with server-side state management, but you need either intelligent load-balancing (to always forward requests from a client to the same server) or centralized state management (where state is stored in a central database that all Web servers access).
Advantages of Server – Side State Management:
Better security: Client-side state management information can be captured (either in transit or while it is stored on the client) or maliciously modified. Therefore, you should never use client-side state management to store confidential information, such as a password, authorization level, or authentication status.
Reduced bandwidth: If you store large amounts of state management information, sending that information back and forth to the client can increase bandwidth utilization and page load times, potentially increasing your costs and reducing scalability. The increased bandwidth usage affects mobile clients most of all, because they often have very slow connections. Instead, you should store large amounts of state management data (say, more than 1 KB) on the server