来自于:cqulyk
    在一般处理程序中使用Session必须要继承IRequiresSessionState接口

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using System.Web.SessionState;
    6. namespace 验证码
    7. {
    8. /// <summary>
    9. /// Summary description for ValidateCheckCode1
    10. /// </summary>
    11. public class ValidateCheckCode1 : IHttpHandler,IRequiresSessionState
    12. {
    13. public void ProcessRequest(HttpContext context)
    14. {
    15. context.Response.ContentType = "text/plain";
    16. string checkCodeRequested = context.Request["checkCode"];
    17. string checkCodeInSession = (string)context.Session["CheckCode"];
    18. if (checkCodeRequested.Equals(checkCodeInSession))
    19. {
    20. context.Response.Write("{\"retrunCode\":" + 0 + "}");
    21. }
    22. else
    23. {
    24. context.Response.Write("{\"retrunCode\":" + -1 + "}");
    25. }
    26. }
    27. public bool IsReusable
    28. {
    29. get
    30. {
    31. return false;
    32. }
    33. }
    34. }
    35. }