Gets the HttpSessionState instance for the current request.
Assembly: System.Web.Services (in System.Web.Services.dll)
Syntax
An HttpSessionState representing the ASP.NET session state object for the current session.
<[%$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.SessionStateHttpSessionStateAn 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"]);
}
}
Platforms
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.