使用HttpApplicationState实现一个点击计数器

ZDNet软件频道 时间:2003-01-17 作者:Techmail 代码页 |  我要评论()
本文关键词:


Imports System.Web.Services

<WebService(Namespace := "http://tempuri.org/")> _
Public Class WSCounter
    Inherits System.Web.Services.WebService

    Private Sub IncrementGlobalCounter()
        Application.Lock()
        Application("GlobalCounter") += 1
        Application.UnLock()
    End Sub

    Private Sub IncrementSpecificCounter(ByVal CounterName As String)
        Application.Lock()
        Application(CounterName) += 1
        Application.UnLock()
    End Sub

    <WebMethod()> Public Sub Method1()
        ' Increment the global Web Service counter
        Me.IncrementGlobalCounter()

        'execute Web method code........
    End Sub

    <WebMethod()> Public Sub Method2()
        'Increment the global Web service counter
        Me.IncrementGlobalCounter()

        'Increment the Web Service specific counter
        Me.IncrementSpecificCounter("WSCounter")

        'execute Web method code......
    End Sub

    <WebMethod()> Public Function GetGlobalCounter() As String
        Return Application("GlobalCounter")
    End Function

  <WebMethod()> Public Function GetSpecificCounter(ByVal CounterName) _
                 As String
        Return Application(CounterName)
    End Function

End Class

百度大联盟认证黄金会员Copyright© 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备09041801号-159
京公网安备:1101082134