WebService.Session Property
Gets the HttpSessionState instance for the current request.
[Visual Basic] Public ReadOnly Property Session As HttpSessionState [C#] public HttpSessionState Session {get;} [C++] public: __property HttpSessionState* get_Session(); [JScript] public function get Session() : HttpSessionState;
Property Value
A System.Web.HttpSessionState representing the ASP.NET session state object for the current session.
Example
[Visual Basic, C#] The example below uses session state to determine how many times a particular session accesses the XML Web service method SessionHitCounter. In this example, the EnableSession property of the WebMethodAttribute is set to true in order to gain access to session state.
[Visual Basic] <%@ WebService Language="VB" Class="Util" %> Imports System.Web.Services Public Class Util Inherits WebService <WebMethod(Description := "Per session Hit Counter", _ EnableSession := True)> _ Public Function SessionHitCounter() As Integer If Session("HitCounter") Is Nothing Then Session("HitCounter") = 1 Else Session("HitCounter") = CInt(Session("HitCounter")) + 1 End If Return CInt(Session("HitCounter")) End Function End Class [C#] <%@ WebService Language="C#" Class="Util" %> using System.Web.Services; public class Util: WebService { [ WebMethod(Description="Per session Hit Counter",EnableSession=true)] public int SessionHitCounter() { if (Session["HitCounter"] == null) { Session["HitCounter"] = 1; } else { Session["HitCounter"] = ((int) Session["HitCounter"]) + 1; } return ((int) Session["HitCounter"]); } }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
WebService Class | WebService Members | System.Web.Services Namespace | HttpSessionState