Exemplo n.º 1
0
    public static void NewCode(string vctype)
    {
        CaptchaImage validate = new CaptchaImage(12, 50);

        validate.strFont   = "宋体";
        validate.nFontSize = 13;
        MemoryStream stream = validate.GetCode(1, 4, 58, 22);
        Guid         id;

        lock (CodeCache)
        {
            id            = Guid.NewGuid();
            CodeCache[id] = new CodeInf {
                Code = validate.strValidate, Time = DateTime.Now
            };
        }
        var Response = System.Web.HttpContext.Current.Response;

        Response.Cookies.Add(new HttpCookie("vc_" + vctype, id.ToString())
        {
            HttpOnly = true
        });
        Response.ContentType = "image/jpeg";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Clear();
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        Response.End();
    }