State persistence introduction for ASP.NET Web Forms apps

Until this point in the BTI420 course, you have been using simple on-page methods to persist data. For example, you have been using labels, by round-tripping data in your code.

You also have been taking advantage of a built-in feature of ASP.NET (maybe without knowing it), which preserves web control state as the user interacts with a web form. For example, when a web form user makes a selection in a list control, that selection persists after a postback.

Now it is time to learn more about persisting data in ASP.NET web applications.

State persistence highlights

Now it is time to learn more about persisting data in ASP.NET web applications. Go through this state management slide deck before continuing here.

Welcome back. Now you know that there are tactics we can use to persist data. In our BTI420 Web Forms apps, we will tend to use two:

Query strings

Session state

Using session state

Now that you know and understand something about the state persistence problem, what do you do about it?

Well, use state management, specifically session state.

And, for your warp server apps, implement session state by using a session state server. (Local "file system" web site apps cannot use a session state server.)

Make sure the "sessionState" element in Web.config is configured for "StateServer", as shown in the following excerpt:

<sessionState mode="StateServer" />

If YOUR web site does not yet have the "sessionState" element, create it. Its direct parent element is <system.web>. (Therefore, you can place it anywhere in <system.web> as a direct child of <system.web>.)

Why will we use session state?

We need to persist data that is often in the form of objects. You are simply unable to conveniently persist such objects with other techniques. For example, you will be persisting:

Authenticated user state data, probably using an instance of a class (you have written) that represents an authenticated user

Data sets, or another data structure, which includes the results from a database query, or other operation