SessionCounter.asmx 854 B

1234567891011121314151617181920212223242526272829303132333435
  1. <%@ WebService Language="c#" Class="Util.SessionCounter" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.Services;
  5. using System.Web.SessionState;
  6. namespace Util
  7. {
  8. public class SessionCounter: System.Web.Services.WebService
  9. {
  10. public SessionCounter ()
  11. {
  12. if (Context == null)
  13. throw new Exception ("Context not set in constructor");
  14. }
  15. [ WebMethod(EnableSession=true) ]
  16. public void Reset()
  17. {
  18. Session["counter"] = 0;
  19. }
  20. [ WebMethod(EnableSession=true) ]
  21. public int AddOne()
  22. {
  23. if ( Session["counter"] == null )
  24. { Session["counter"]=0; }
  25. else
  26. { Session["counter"]=(int)Session["counter"]+1; }
  27. return (int)Session["counter"];
  28. }
  29. }
  30. }