我想将用户登陆代码写在ashx中,大体如下:
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string type = context.Request.QueryString["type"];
        if (type == "1")
        {
            IUserBll bll = new ManagerBll();
            string username = context.Request.QueryString["name"];
            string password = context.Request.QueryString["pass"];
            if (bll.Login(username, password))
            {
                context.Session.Add("session_username", username);
                HttpCookie cookie = new HttpCookie("edou_username");
                cookie.Value = username;
                cookie.Expires = DateTime.Now.AddDays(1);
                context.Response.AppendCookie(cookie);
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendFormat("<div>欢迎<font color=#ff0000>{0}</font></div>", username);
                sb.AppendFormat("<div><a href='{0}'>进入管理中心</a></div>", "../manage/ask_list.htm");
                sb.Append("<div id='mytitle'></div>");
                context.Response.Write(sb.ToString());
            }
            else
            {
                context.Response.Write("0");
            }
        }
        else
        {
            HttpCookie cookie = context.Response.Cookies["edou_username"];
            object obj = context.Session["session_username"];
            if (obj == null && (cookie == null || string.IsNullOrEmpty(cookie.Value) || cookie.Expires < DateTime.Now))
            {
                context.Response.Write("1");
            }
            else
            {
                string username = string.Empty;
                if (obj == null)
                    username = cookie.Value;
                else
                    username = obj.ToString();
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.AppendFormat("<div>欢迎<font color=#ff0000>{0}</font></div>", username);
                sb.AppendFormat("<div><a href='{0}'>进入管理中心</a></div>", "../manage/ask_list.htm");
                sb.Append("<div id='mytitle'></div>");
                context.Response.Write(sb.ToString());
            }
        }
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }但是不知道为什么,读取cookie的时候,总是得不到cookie的值???