Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Web Services QuickStart Tutorial

Intrinsics (ASP.NET Session and Application State Management)

ASP.NET Web Services allows you to access the underlying state management provided by ASP.NET. To enable ASP.NET session state, set WebMethod.EnableSession = True. On the client you must also set serviceName.CookieContainer to a new instance of System.Net.CookieContainer. This allows you to persist data within the same session. Note that to persist data for the entire application (for all incoming requests to the service), neither step is required.

Client-Side Code

   //On the client you must add the following code (for session state only):
   serviceName.CookieContainer = new System.Net.CookieContainer();

Server-Side Code

   //Setting EnableSession to true allows state to be persisted per Session
   public String UpdateSessionHitCounter() {
      //update the session "HitCounter" here
      return Session["HitCounter"].ToString();

   //Note that state can be persisted for the entire Application even if EnableSession is false
   public String UpdateApplicationHitCounter() {
      //update the application "HitCounter" here
      return Application["HitCounter"].ToString();

VB Sample Caption
Run Sample View Source

Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.