Session在自定义IHTTPHander中的用法

<%@ WebHandler Language="C#" Class="FormValidator" %>



using System;

using System.Web;



public class FormValidator : IHttpHandler, System.Web.SessionState.IRequiresSessionState{

    

    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/plain";

        string type = context.Request["type"];

        bool status = false;

        

        if (!string.IsNullOrEmpty(type))

        {

            Maitonn.BLL.UserBLL user = Maitonn.BLL.UserBLL.CreateInstance();

            switch (type)

            { 

                case "email":

                    string email=context.Request["Vemail"];

                    status = !user.ExsitEmail(email);

                    break;

                case "nid":

                    string nid = context.Request["Vnid"];

                    status = !user.ExsitNid(nid);

                    break;

                case "vcode":

                    string vcode = context.Request["Vvcode"];

                    if (context.Session["VCode"] != null)

                    { 

                        status= context.Session["VCode"].ToString().Equals(vcode, StringComparison.OrdinalIgnoreCase);

                    }

                    break;

            }

        }

        context.Response.Write(string.Format("{{res:{0}}}", status));

    }

 

    public bool IsReusable {

        get {

            return false;

        }

    }



}

需要继承System.Web.SessionState.IRequiresSessionState接口才能具有访问Session的权限,不然访问时为空.

你可能感兴趣的:(session)