Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

Remembering a visitor between pages

Pages do not remember each other by default. Session state gives one visitor a small store that lasts while they browse.

Store and read

C#
// on one page
Session["userName"] = txtName.Text;

// on a later page
string who = Session["userName"] as string;

What to keep in mind

  • Session belongs to one visitor, not to everyone.
  • It ends when the session times out, so never treat it as permanent storage.
  • Anything important belongs in a database, not in session.
Small values only. Session is for a name, an identifier or a setting. A large object in session slows the server and surprises the next developer.

With pages, input and memory in place, you can apply all of it in a worked shopping cart example.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.