Home > 2010 Winter BTI420 > State persistence introduction for ASP.NET Web Forms apps

State persistence introduction for ASP.NET Web Forms apps

January 28, 2010 Leave a comment Go to comments

This post discusses session state, a mechanism for persisting data while a browser user interacts with your ASP.NET Web Forms app.

 

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

statethumbnail 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:

  1. Query strings
  2. 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

Now can you see why you need session state?

 


Advertisements
Categories: 2010 Winter BTI420
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: