Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

ASP.NET 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()
VB


Server-Side Code

		
   'Setting EnableSession to true allows state to be persisted per Session
   <WebMethod(EnableSession:=True)> _
   Public Function UpdateSessionHitCounter() As String
      'update the session "HitCounter" here
      Return Session("HitCounter").ToString()
   End Function

   'Note that state can be persisted for the entire Application even if EnableSession is false
   <WebMethod(EnableSession:=False)> _
   Public Function UpdateApplicationHitCounter() As String
      'update the application "HitCounter" here
      Return Application("HitCounter").ToString()
   End Function
VB


VB Sample Caption
Run Sample View Source



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