WebService.Application WebService.Application WebService.Application WebService.Application Property

定义

获取当前 HTTP 请求的应用程序对象。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; }
member this.Application : System.Web.HttpApplicationState
Public ReadOnly Property Application As HttpApplicationState

属性值

示例

下面的示例演示一个命中计数器, 每次浏览器调用 XML Web service 方法时递增计数。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

注解

XML Web services 可以同时使用应用程序状态和会话状态。XML Web services can use both application state and session state. 无论是否关闭方法的会话状态 (通过使用EnableSession的属性WebMethodAttribute), 都将在访问 XML Web service 的所有会话中维护应用程序状态。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).

适用于

另请参阅