请任何人告诉我,这个eroor在asp.net中是什么意思?
问题描述:
大家好,
我在vb.net中有以下课程:
Hi all ,
I have the following class in vb.net :
Imports System.Data
Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Collections.Generic
Public Class Myhandler
Inherits System.Web.UI.Page
Implements IHttpModule
Private _page As Page = Nothing
Private temp As Queue(Of String)
Public Sub New()
temp = New Queue(Of String)()
End Sub
Public Shadows Sub Init(context As HttpApplication) Implements IHttpModule.Init
AddHandler context.PreRequestHandlerExecute, New EventHandler(AddressOf context_PreRequestHandlerExecute)
End Sub
Private Sub context_PreRequestHandlerExecute(sender As Object, e As EventArgs)
Dim _httpContext As System.Web.HttpContext = System.Web.HttpContext.Current
If _httpContext IsNot Nothing Then
_page = TryCast(_httpContext.Handler, System.Web.UI.Page)
If _page IsNot Nothing Then
AddHandler _page.Init, New EventHandler(AddressOf _page_Init)
AddHandler _page.Load, New EventHandler(AddressOf _page_Load)
Else
Return
End If
Else
Return
End If
End Sub
Private Sub _page_Init(sender As Object, e As EventArgs)
Dim hdnGuid As New HiddenField()
hdnGuid.ID = "hdnGuid"
If Not _page.IsPostBack Then
hdnGuid.Value = Guid.NewGuid().ToString()
End If
_page.Form.Controls.Add(hdnGuid)
End Sub
Private Sub _page_Load(sender As Object, e As EventArgs)
Dim h1 As HiddenField = DirectCast(_page.Form.FindControl("hdnGuid"), HiddenField)
Dim currentGuid As New GuidClass()
currentGuid.Guid = h1.Value
Dim _httpContext As System.Web.HttpContext = System.Web.HttpContext.Current
If temp.Contains(Of String)(currentGuid.Guid) Then
_httpContext.Items.Add("IsRefresh", True)
Else
If Not (currentGuid.Guid.Equals(Nothing) OrElse currentGuid.Guid.Equals("")) Then
temp.Enqueue(currentGuid.Guid)
End If
_httpContext.Items.Add("IsRefresh", False)
End If
End Sub
End Class
并生成此错误:编译器错误消息:BC30149:类``Myhandler''必须为接口``System.Web.IHttpModule''实现``Sub Dispose()''.
在此先感谢.
And this error is generated:Compiler Error Message: BC30149: Class ''Myhandler'' must implement ''Sub Dispose()'' for interface ''System.Web.IHttpModule''.
Thanks in advance.
答
我与ASP.NET没有任何关系.这是因为System.Web.IHttpModule
具有方法Dispose
(还有Init
).接口实现规则要求您同时实现这两种方法.做到这一点,但首先要了解原因.请参阅 http://msdn.microsoft.com/en-us/library/system.web .ihttpmodule.aspx [ ^ ].
我还建议您在进入ASP.NET之前先熟悉一下编程,OOP和.NET的基础知识.首先,只需要通过控制台应用程序来熟悉这些内容就可以了.在诸如APS.NET之类的更复杂的领域中走得太远,只会浪费太多时间并造成太多挫败感.
祝你好运,—SA
I has nothing to do with ASP.NET. This is becauseSystem.Web.IHttpModule
has the methodDispose
(and alsoInit
). The rules for implementation of interfaces require that you implement both methods. Do it, but first learn why. See http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx[^].
I would also recommend that you became comfortable with basics of programming, OOP and .NET before getting to ASP.NET. Getting familiar with this stuff doing your exercises with just console application at first would be much more appropriate. Going too far in more complex fields like APS.NET you will only loose too much time and create too much frustration.
Good luck,—SA