asp.net使用ashx生成图形验证码的方法示例
YPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
项ç®å¨å¼åçæ¶åéè¦æ·»å åç§åæ ·çåè½ï¼ä»å¤©æ们添å äºè¿ä¸ªç±»ï¼å¯ä»¥è®©æ们å¨ä½¿ç¨éªè¯ç çæ¶åç´æ¥è°ç¨ï¼ä»å¤©ç±ç«ææ¯é¢éå°ç¼ä¸ºå¤§å®¶å¸¦æ¥äºasp.net使ç¨ashxçæå¾å½¢éªè¯ç çæ¹æ³ç¤ºä¾ï¼å¤§å®¶å¿«æ¥ä¸æåèå§ï¼
è¿ä¸ªä»£ç ççå°±è§å¾å代ç ç人æ¯è¾æ¬ æï¼ä»£ç åæè¿æ ·åçå®éé·ãéªè¯åä¹ä¸åç¹scriptåä¸åæ¢ã
ä¸é¢æä»ç»ä¸ç§æ¹å¼æ¥å®ç°è¿æ ·çåè½
1. å个ashxçæå¾å½¢éªè¯ç
using System; using System.Collections; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; using System.Web.SessionState; using System.Drawing; namespace usechecknum.ashx { ////// $codebehindclassname$ çæè¦è¯´æ /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class doCreateNum : IHttpHandler,IRequiresSessionState { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string checkCode = GetValidation(5); // 产ç5ä½éæºéªè¯ç å符 context.Session["Code"] = checkCode; //å°å符串ä¿åå°Sessionä¸ï¼ä»¥ä¾¿éè¦æ¶è¿è¡éªè¯ System.Drawing.Bitmap image = new System.Drawing.Bitmap(70, 22); Graphics g = Graphics.FromImage(image); try { //çæéæºçæå¨ Random random = new Random(); //æ¸ ç©ºå¾çèæ¯è² g.Clear(Color.White); // ç»å¾ççèæ¯åªé³çº¿ int i; for (i = 0; i
2. å¨é¡µé¢ä¸æ¾ç¤ºéªè¯ç ï¼å 为æ们çæçæ¯å¾å½¢ï¼æ以å¯ä»¥ç´æ¥åå¨æ ç¾éï¼æ们åªè¦å段ç®åçèæ¬å°±å¯ä»¥ç¹å»é¼ æ åæ¢éªè¯ç äº
éªè¯ç ç使ç¨
说äºå天ï¼è¯¥æ¯æ¶åçççæçéªè¯ç é¿ä»ä¹æ ·äº
éè¿ç±ç«ææ¯é¢éä»ç»çasp.net使ç¨ashxçæå¾å½¢éªè¯ç çæ¹æ³ç¤ºä¾ï¼å ¶å®å¾å¤äººé½çè¡·äºç 究è¿äºå¿«æ·æ¹æ³ï¼æ以å¾å¾ä¼åºä¸äºé误ï¼å°ç¼å»ºè®®å¤§å®¶è¿æ¯è®¤çåæ项ç®çåºæ¬é¢ã