state is implemented by a view state object that retains the values of page and control properties that change from one execution of a page to another. These values are encoded in a string that’s assigned to a hidden input field that’s passed to and from the browser.• Two reasons for disabling view state for a page or control are (1) because view state restores data that you don’t want restored, and (2) because view state storage is so large that it affects the performance of the page.• ASP.NET uses session state to track each user’s session. To do that, it cre-ates a session state object that contains a session ID, and it passes this ID to and from the browser. The server uses this ID to get the session state object for the user.• To work with the items in a view state object or a session state object, you can use the indexer, properties, and methods of their classes: the StateBag class for view state and the HttpSessionState class for session state.• To get data from a session state object, you often use the Load event handler for a page. To get or update the data in the object, you can use any event handler. And to update value-based data, you can use the PreRender event handler, although you don’t need to do that for reference-based data.• Although cookies are normally used to pass the session ID for a session state object to and from the browser, you can also set up cookie less session tracking. Then, the session ID is coded in the URL for the page. A third option uses a cookie if cookies are supported by a browser or the URL if they aren’t.• When an application starts, ASP.NET creates an application object, an application state object, and a cache object. These objects exist as long as the application is running on IIS, and items stored in the application state object and cache object are available to all users of the application.• The application state object is best used for small items of data, but the cache object can be used for larger items since they don’t have to stay in server memory until the application ends. Instead, cache items can have expiration dates, and they can be scavenged by the server if memory is needed.• You can create a Global.asax file for an application that lets you create event handlers for application and session events like the start or end of an applica¬tion or session.• A cookie is a name/value pair that’s stored in the user’s browser or on the user’s disk. A web application can send a cookie to a browser in an HTTP response. Then, the browser returns the cookie in its HTTP request.• A session cookie exists only for the duration of a browser session. A persis¬tent cookie is kept on the user’s disk and is retained until the cookie expires.• URL encoding lets you pass data from one page of an application to another by attaching name/value pairs in a query string at the end of the URL
đang được dịch, vui lòng đợi..
