Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

I have the following class in vb.net :

VB
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


And this error is generated:Compiler Error Message: BC30149: Class 'Myhandler' must implement 'Sub Dispose()' for interface 'System.Web.IHttpModule'.

Thanks in advance.
Posted

1 solution

I has nothing to do with ASP.NET. This is because System.Web.IHttpModule has the method Dispose (and also Init). 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
 
Share this answer
 
v2
Comments
Simon Bang Terkildsen 30-Aug-11 16:03pm    
System.Web.IHttpModule does not inherit from System.IDisposable however it defines it's own Dispose method aswell as an Init method
Sergey Alexandrovich Kryukov 30-Aug-11 16:05pm    
Oh, my mistake. I just assumed it does. Thank you very much; I'll fix it.
--SA
Simon Bang Terkildsen 30-Aug-11 16:57pm    
No problem at all. You've finally showed that you indeed are fallible, as the rest of us ;)
Sergey Alexandrovich Kryukov 30-Aug-11 16:10pm    
See the updated solution. Implement both methods of System.Web.IHttpModule.
Add public sub Dispose() to Myhandler and implement it. You already done Init but Dispose is missing.
--SA
mhamad zarif 30-Aug-11 16:13pm    
ok thanks now i understood what is the problem.Since i know that you are generous and one of the best helpers on code project,i want to ask for your help about a problem that i have been facing since 3 days.So can you help me ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900