温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Vb.net验证码控件及Demo源码
当前文件:
VBCaptcha/WebControlCaptcha/CaptchaImageHandler.vb,打开代码结构图
VBCaptcha/WebControlCaptcha/CaptchaImageHandler.vb,打开代码结构图1Imports System 2
Imports System.Web 3
Imports System.Drawing 4
5
''' <summary> 6
''' Captcha image stream HttpModule. Retrieves CAPTCHA objects from cache, renders them to memory, 7
''' and streams them to the browser. 8
''' </summary> 9
''' <remarks> 10
''' You *MUST* enable this HttpHandler in your web.config, like so: 11
''' 12
''' <httpHandlers> 13
''' <add verb="GET" path="CaptchaImage.aspx" type="WebControlCaptcha.CaptchaImageHandler, WebControlCaptcha" /> 14
''' </httpHandlers> 15
''' 16
''' Jeff Atwood 17
''' http://www.codinghorror.com/ 18
'''</remarks> 19
Public Class CaptchaImageHandler 20
Implements IHttpHandler 21
22
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest 23
Dim app As HttpApplication = context.ApplicationInstance 24
25
'-- get the unique GUID of the captcha; this must be passed in via the querystring 26
Dim guid As String = app.Request.QueryString("guid") 27
Dim ci As CaptchaImage = Nothing 28
29
If guid <> "" Then 30
If String.IsNullOrEmpty(app.Request.QueryString("s")) Then 31
ci = CType(HttpRuntime.Cache.Get(guid), CaptchaImage) 32
Else 33
ci = CType(HttpContext.Current.Session.Item(guid), CaptchaImage) 34
End If 35
36
End If 37
38
If ci Is Nothing Then 39
app.Response.StatusCode = 404 40
context.ApplicationInstance.CompleteRequest() 41
Return 42
End If 43
44
'-- write the image to the HTTP output stream as an array of bytes 45
Dim b As Bitmap = ci.RenderImage 46
b.Save(app.Context.Response.OutputStream, Drawing.Imaging.ImageFormat.Jpeg) 47
b.Dispose() 48
app.Response.ContentType = "image/jpeg" 49
app.Response.StatusCode = 200 50
context.ApplicationInstance.CompleteRequest() 51
End Sub 52
53
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable 54
Get 55
Return True 56
End Get 57
End Property 58
59
End Class







