asp.net服务端控件之 图形验证码
2010-05-04 02:37
363 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Drawing; namespace WebApplication2 { [DefaultProperty("Text")] [ToolboxData("<{0}:VerificationCode runat=server></{0}:VerificationCode>")] public class VerificationCode : WebControl,IHttpHandler { private String _code="Hello"; public String Code { get { return _code; } set { _code = value; } } public VerificationCode() : base(HtmlTextWriterTag.Img) { } protected override void AddAttributesToRender(HtmlTextWriter writer) { base.AddAttributesToRender(writer); writer.AddAttribute("onclick", "this.src=this.src+'?'"); writer.AddAttribute(HtmlTextWriterAttribute.Src, "img.Seven"); writer.AddAttribute("alt", "Click To Reload"); } protected override void RenderContents(HtmlTextWriter output){} bool IHttpHandler.IsReusable { get { return true; } } void IHttpHandler.ProcessRequest(HttpContext context) { MemoryStream ms = new MemoryStream(); Bitmap img = new Bitmap(100, 30); Graphics g = Graphics.FromImage(img); g.Clear(ColorTranslator.FromHtml("#CCCCCC")); g.DrawString(Code, new Font("宋体", 12), Brushes.Black, 10, 10); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); this.Context.Response.Clear(); this.Context.Response.ContentType = "image/jpeg"; this.Context.Response.BinaryWrite(ms.ToArray()); img.Dispose(); ms.Close(); g.Dispose(); this.Context.Response.End(); } } }
wenconfig System.web
<add verb="*" path="*.YourTypeName" type="Yournamespace.className"/>
相关文章推荐
- ASP.NET图形验证码控件
- [ASP.NET 控件实作 Day28] 图形验证码控件
- asp.net生成字母和数字混合图形验证码
- Ajax 实现在WebForm中拖动控件并即时在服务端保存状态数据 (Asp.net 2.0)(示例代码下载)
- asp.net生成字母和数字混合图形验证码
- ASP.NET验证码控件-AutoAuthCode v1.5
- Asp.net中服务端控件事件是如何触发的
- ASP.NET生成图形验证码的方法详解
- asp.net扩展Login控件,添加图文验证码
- asp.net使用ashx生成图形验证码的方法示例
- ASp.Net自定义验证码控件
- 客户端触发Asp.net中服务端控件事件
- asp.net 如何获取一个服务端控件的innerHtml
- asp.net 服务端验证控件 和 OnClientClick 冲突
- asp.net扩展Login控件,添加图文验证码
- (转)客户端触发Asp.net中服务端控件事件
- 32款AJAX ASP.NET服务端控件介绍及代码(推荐)
- Asp.Net Ajax服务端控件
- ASP.net验证码控件(附源代码)
- Asp.net 实现验证码功能的Web控件