WebService.Session Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the HttpSessionState instance for the current request.
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
Property Value
An HttpSessionState representing the ASP.NET session state object for the current session.
- Attributes
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="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
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET