WebService.Session Proprietà

Definizione

Ottiene l'istanza HttpSessionState per la richiesta corrente.

public:
 property System::Web::SessionState::HttpSessionState ^ Session { System::Web::SessionState::HttpSessionState ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.SessionState.HttpSessionState Session { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Session : System.Web.SessionState.HttpSessionState
Public ReadOnly Property Session As HttpSessionState

Valore della proprietà

HttpSessionState

Istanza HttpSessionState che rappresenta l'oggetto dello stato sessione ASP.NET per la sessione corrente.

Attributi

Esempio

L'esempio seguente usa lo stato della sessione per determinare il numero di volte in cui una sessione specifica accede al metodo SessionHitCounterdel servizio Web XML . In questo esempio la EnableSession proprietà dell'oggetto è impostata su true per ottenere l'accesso WebMethodAttribute allo stato della sessione.

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

Si applica a

Vedi anche