放逐忧伤

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<%@ 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的权限,不然访问时为空.
posted on 2011-05-25 15:47  放逐忧伤  阅读(349)  评论(0)    收藏  举报