您目前尚未登陆,请选择【登陆】或【注册
首页->控件插件->Vb.net验证码控件及Demo源码>>WebControlCaptcha/CaptchaControl.vb>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Vb.net验证码控件及Demo源码
当前文件:文件类型 VBCaptcha/WebControlCaptcha/CaptchaControl.vb打开代码结构图
普通视图
		            
1Imports System.ComponentModel 2Imports System.Web 3Imports System.Web.UI 4Imports System.Web.UI.WebControls 5Imports System.Collections 6Imports System.Collections.Specialized 7 8''' <summary> 9''' CAPTCHA ASP.NET 2.0 user control 10''' </summary> 11''' <remarks> 12''' add a reference to this DLL and add the CaptchaControl to your toolbox; 13''' then just drag and drop the control on a web form and set properties on it. 14''' 该源码下载自www.51aspx.com(51aspx.com) 15''' Jeff Atwood 16''' http://www.codinghorror.com/ 17''' </remarks> 18<DefaultProperty("Text")> _ 19Public Class CaptchaControl 20 Inherits System.Web.UI.WebControls.WebControl 21 Implements INamingContainer 22 Implements IPostBackDataHandler 23 Implements IValidator 24 25 Public Enum Layout 26 Horizontal 27 Vertical 28 End Enum 29 30 Public Enum CacheType 31 HttpRuntime 32 Session 33 End Enum 34 35 Private _timeoutSecondsMax As Integer = 90 36 Private _timeoutSecondsMin As Integer = 3 37 Private _userValidated As Boolean = True 38 Private _text As String = "Enter the code shown:" 39 Private _font As String = "" 40 Private _captcha As CaptchaImage = New CaptchaImage 41 Private _layoutStyle As Layout = Layout.Horizontal 42 Private _prevguid As String 43 Private _errorMessage As String = "" 44 Private _cacheStrategy As CacheType = CacheType.HttpRuntime 45 46Public Properties 266 267 Public Sub Validate() Implements System.Web.UI.IValidator.Validate 268 '-- a no-op, since we validate in LoadPostData 269 End Sub 270 271 Private Function GetCachedCaptcha(ByVal guid As String) As CaptchaImage 272 If _cacheStrategy = CacheType.HttpRuntime Then 273 Return CType(HttpRuntime.Cache.Get(guid), CaptchaImage) 274 Else 275 Return CType(HttpContext.Current.Session.Item(guid), CaptchaImage) 276 End If 277 End Function 278 279 Private Sub RemoveCachedCaptcha(ByVal guid As String) 280 If _cacheStrategy = CacheType.HttpRuntime Then 281 HttpRuntime.Cache.Remove(guid) 282 Else 283 HttpContext.Current.Session.Remove(guid) 284 End If 285 End Sub 286 287 ''' <summary> 288 ''' are we in design mode? 289 ''' </summary> 290 Private ReadOnly Property IsDesignMode() As Boolean 291 Get 292 Return HttpContext.Current Is Nothing 293 End Get 294 End Property 295 296 ''' <summary> 297 ''' Validate the user's text against the CAPTCHA text 298 ''' </summary> 299 Private Sub ValidateCaptcha(ByVal userEntry As String) 300 301 If Not Visible Or Not Enabled Then 302 _userValidated = True 303 Return 304 End If