280 likes | 445 Views
Asp.net. Page tracing, state management. Using View state. View state. One of the most common way to store information Can be used to web controls, simple data types and custom objects. The viewstate collection. ViewState property. Making view state secure.
E N D
Asp.net Page tracing, state management
View state • One of the most common way to store information • Can be used to web controls, simple data types and custom objects
The viewstate collection • ViewState property
Making view state secure • The view-state information is simply patched together in memory and converted to a Base64 string. • Tamper-Proof View State • Hash code is a cryptographically strong checksum.
Private view state • If information is secret, enable view-state encryption. • Or use the web.config • Always • Never • Auto - Page.RegisterRequiresViewStateEncryption() should be used to encrypt
Storing custom objects • Use serialization to convert it to stream of bytes to be added to the hidden input field page.
Storing // Store a customer in view state. Customer cust = new Customer("Marsala", "Simons"); ViewState["CurrentCustomer"] = cust; • Retrieving // Retrieve a customer from view state. Customer cust; cust= (Customer)ViewState["CurrentCustomer"];
Cross-page posting • A cross-page postback is a technique that extends the postback mechanism you’ve already learned about so that one page can send the user to another page, complete with all the information for that page.
The query string • Passing information by using a query string in the URL http://www.google.com/search?q=organic+gardening • Sending Response.Redirect(“newpage.aspx?recordID=10”); • Receiving String ID= Request.QuertyString[‘recordID’];
url encoding • Allowed characters – alphanumeric and $-_.+!*’(), • Some browsers are tolerant than others • & and # are have special meanings • Encode to replace special characters - & %26
Small files that are created in the web browser’s memory (if they’re temporary) or on the client’s hard drive (if they’re permanent). • One advantage of cookies is that they work transparently, without the user being aware that information needs to be stored. • They also can be easily used by any page in your application and even be retained between visits, which allows for truly long-term storage. • They suffer from some of the same drawbacks that affect query strings—namely, they’re limited to simple string information, and they’re easily accessible and readable if the user finds and opens the corresponding file.
Some users disable cookies on their browsers, which will cause problems for web applications that require them. • Also, users might manually delete the cookie files stored on their hard drives. But for the most part, cookies are widely adopted and used extensively on many websites. • Use System.Net
Managing session state • Allows data storage in the memory • Protected and not transmitted to the client • Every client has a different session and distinct collection of information
Session tracking • Using cookies • Using modified URLS
Session state can be lost in several ways • If the user closes and restarts the browser • If the user accesses the same page through a different browser windows • If the session times out due to inactivity • If your web page code ends the session by calling the Session.Abandon() method