WebService.Session (Propiedad)
Obtiene la instancia de HttpSessionState para la solicitud actual.

Espacio de nombres: System.Web.Services
Ensamblado: System.Web.Services (en system.web.services.dll)

Sintaxis

Visual Basic (Declaración)
Public ReadOnly Property Session As HttpSessionState
Visual Basic (Uso)
Dim instance As WebService
Dim value As HttpSessionState

value = instance.Session
C#
public HttpSessionState Session { get; }
C++
public:
property HttpSessionState^ Session {
    HttpSessionState^ get ();
}
J#
/** @property */
public HttpSessionState get_Session ()
JScript
public function get Session () : HttpSessionState
XAML
No aplicable.

Valor de propiedad

Objeto HttpSessionState que representa el objeto de estado de sesión de ASP.NET para la sesión actual.
Ejemplo

En el siguiente ejemplo se usa el estado de sesión para determinar cuántas veces una sesión determinada tiene acceso al método de servicios Web XML SessionHitCounter. En este ejemplo, la propiedad EnableSession de WebMethodAttribute se establece en true para obtener acceso al estado de sesión.

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"]);
    }   
 }
Plataformas

Windows 98, Windows 2000 Service Pack 4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

Información de versión

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0
Vea también

Page view tracker