Bewerken

Delen via


WebService.Application Property

Definition

Gets the application object for the current HTTP request.

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

Property Value

An HttpApplicationState object.

Attributes

Examples

The example below demonstrates a hit counter, incrementing the count every time a browser calls the XML Web service method.

<%@ WebService Language="C#" Class="Util"%>
 using System.Web.Services;
 
 public class Util: WebService {
   [ WebMethod(Description="Application Hit Counter",EnableSession=false)]
    public int HitCounter() {
       if (Application["HitCounter"] == null) {
          Application["HitCounter"] = 1;
       }
       else {
          Application["HitCounter"] = ((int) Application["HitCounter"]) + 1;
          }
       return ((int) Application["HitCounter"]);
    }   
 }
<%@ WebService Language="VB" Class="Util"%>

Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    <WebMethod(Description := "Application Hit Counter", _
        EnableSession := False)> _
    Public Function HitCounter() As Integer
        
        If Application("HitCounter") Is Nothing Then
            Application("HitCounter") = 1
        Else
            Application("HitCounter") = CInt(Application("HitCounter")) + 1
        End If
        Return CInt(Application("HitCounter"))
    End Function
End Class

Remarks

XML Web services can use both application state and session state. Application state is maintained across all sessions accessing an XML Web service regardless of whether session state is turned off for a method(by using the EnableSession property of the WebMethodAttribute).

Applies to

See also