public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; List <string> showResult = new List <string>(); showResult.Add("Javascript"); showResult.Add("C#"); showResult.Add("VB"); showResult.Add("C++"); showResult.Add("F"); showResult.Add("JAVA"); showResult.Add("PHP"); showResult.Add("Object-C"); showResult.Add("CSS"); showResult.Add("HTML"); int index = UtilNumber.Parse(UtilNumber.RandomNumber(1)); string result = showResult.ElementAt(index); context.Response.Write(result); }
public void ProcessRequest(HttpContext context) { try { int NumCount = 4;//预设产生4位数 //取得亂數 string str_ValidateCode = UtilNumber.RandomNumber(NumCount); /*用於驗證的Session*/ context.Session["ValidateNumber"] = str_ValidateCode; //取得圖片物件 System.Drawing.Image image = UtilImage.CreateCheckCodeImage(str_ValidateCode); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); /*輸出圖片*/ context.Response.Clear(); context.Response.ContentType = "image/jpeg"; context.Response.BinaryWrite(ms.ToArray()); ms.Close(); } catch (Exception ex) { Console.WriteLine("发生异常:" + ex.Message); } }