.NET Framework Class Library
WebServiceSession Property

Gets the HttpSessionState instance for the current request.

Namespace:   System.Web.Services
Assembly:  System.Web.Services (in System.Web.Services.dll)
Syntax
<[%$TOPIC/szk893hf_en-us_VS_110_2_0_0_0_0%](False)> _
Public ReadOnly Property Session As [%$TOPIC/szk893hf_en-us_VS_110_2_0_0_0_1%]
[[%$TOPIC/szk893hf_en-us_VS_110_2_0_1_0_0%](false)]
public [%$TOPIC/szk893hf_en-us_VS_110_2_0_1_0_1%] Session { get; }
[[%$TOPIC/szk893hf_en-us_VS_110_2_0_2_0_0%](false)]
public:
property [%$TOPIC/szk893hf_en-us_VS_110_2_0_2_0_1%]^ Session {
	[%$TOPIC/szk893hf_en-us_VS_110_2_0_2_0_2%]^ get ();
}
[<[%$TOPIC/szk893hf_en-us_VS_110_2_0_3_0_0%](false)>]
member Session : [%$TOPIC/szk893hf_en-us_VS_110_2_0_3_0_1%] with get

Property Value

Type: System.Web.SessionStateHttpSessionState
An HttpSessionState representing the ASP.NET session state object for the current session.
Examples

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.

<%@ 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
<%@ 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"]);
    }   
 }
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.