WebService.Application プロパティ

定義

現在の HTTP 要求に対するアプリケーション オブジェクトを取得します。

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

プロパティ値

HttpApplicationState

HttpApplicationState オブジェクト。

属性

次の例は、ブラウザーが XML Web サービス メソッドを呼び出すたびにカウントをインクリメントするヒット カウンターを示しています。

<%@ 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

注釈

XML Web サービスでは、アプリケーションの状態とセッション状態の両方を使用できます。 アプリケーションの状態は、(メソッドのプロパティWebMethodAttributeを使用してEnableSession) セッション状態がオフになっているかどうかに関係なく、XML Web サービスにアクセスするすべてのセッションにわたって保持されます。

適用対象

こちらもご覧ください