473,503 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question regarding this httpmodule

I wrote a very simple httpmodule and tried to compile it with no success.
This is my code:

==============
Imports System
Imports System.Web
Imports Microsoft.VisualBasic

NameSpace myErrorHandler

Public Class myExceptionHandler
Implements IHttpModule

Public Sub Init (objApp as HttpApplication)
AddHandler objApp.Error, AddressOf Me.OnError
End sub

Public Sub Dispose()

End Sub

Public Sub OnError(Sender as Object, e as EventArgs)
Dim objApp as HttpApplication
objApp = CType(Sender, HttpApplication)
Dim ctx as HttpContext = objApp.Context.Current
Dim exception as Exception = ctx.Server.GetLastError()

Dim errorInfo as string = _
"<br>Offending URL: " & ctx.Request.Url.ToString() & _
"<br>Source: " & exception.Source & _
"<br>Message: " & exception.Message & _
"<br>Stack trace: " & exception.StackTrace

ctx.Response.Write (errorInfo)
End Sub

End Class

End Namespace
==============

I am not too sure how to compile the above code because whenever I tried it,
the vbc compiler said that I have to have init and dispose in order to
implement the IHttpModule interface. The problem is, I do have those 2 subs
in my class?

Can someone point out what's wrong with my code for me?

I used the following command in C:\WINNTS\Microsoft.NET\Framework\v1.1.4322
to compile the code:

vbc /t:library /r:System.dll,System.web.dll PGDErrorHandler.vb
Jul 22 '05 #1
3 2186
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to implement the IHttpModule
in your own class. If there is any misunderstanding, please feel free to
let me know.

In VB.NET, we have add Implements keyword to indicate that the method
implements certain method in an interface. Or the method is considered as a
different one. Here I make some changes to your code. HTH.

Public Sub Init(ByVal objApp As HttpApplication) Implements
System.Web.IHttpModule.Init
AddHandler objApp.Error, AddressOf Me.OnError
End Sub

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

End Sub

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jul 22 '05 #2
Thanks Kevin, the module now compiles correctly. however, I am still not too
sure how to use it to response.write out an error message with the module. I
included a reference in web.config, and created a page with a unhandled
runtime error in it. No matter what error I have, it just does not display
the error message based on what I specified in the module. All it shows is
the standard ASP.NET error page.
Jul 22 '05 #3
Hi ,

I think your code in the OnError handler did get executed. The problem that
you still get the buildin red/yellow exception page is because you didn't
end the response in your OnError handler so that the asp.net runtime
continue to pass the request to the default unhandled error handler and
produce the default exception page.
To avoid this and only output our own error info, we can manualy end the
response in Error event after we've output our own content. For example:

Public Sub OnError(ByVal Sender As Object, ByVal e As EventArgs)
Dim objApp As HttpApplication
objApp = CType(Sender, HttpApplication)
Dim ctx As HttpContext = objApp.Context

ctx.Response.ClearContent()

ctx.Response.Write( "<font size='30' color='red'>unhandled error
occured</font>")

ctx.Response.End()

End Sub

In addition, you can also build a custom error page so that we can use
Server.Transfer to redirect the context to our custom error handling page.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: question regarding this httpmodule
| thread-index: AcWCCRfXvfZq231RTSGw1n1egq22Aw==
| X-WBNR-Posting-Host: 64.180.224.155
| From: =?Utf-8?B?U2FtdWVs?= <pr********@nospam.nospam>
| References: <B6**********************************@microsoft.co m>
<Fv*************@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: question regarding this httpmodule
| Date: Wed, 6 Jul 2005 02:00:01 -0700
| Lines: 6
| Message-ID: <D4**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.general:45503
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| Thanks Kevin, the module now compiles correctly. however, I am still not
too
| sure how to use it to response.write out an error message with the
module. I
| included a reference in web.config, and created a page with a unhandled
| runtime error in it. No matter what error I have, it just does not
display
| the error message based on what I specified in the module. All it shows
is
| the standard ASP.NET error page.
|

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2569
by: nail | last post by:
Folks, I develop a HttpModule and it works correct, but one problem is occurs. After I register the httpmodule in the web.config, my pages (not testing http://localhost/site but...
4
3899
by: Danny W | last post by:
Hi There! Is it possible to use HttpModule to replace the built-in ASP.NET Session object? I want to write a HttpModule that will handle storing and retrieving of session values from an external...
5
1393
by: Raj | last post by:
Hi there, I have written a small httpmodule which basically scan the incoming request on a perticular domain and pass the url based on mappings. more like a url rewriter e.g....
2
2126
by: Simon-Pierre Jarry | last post by:
Hi, I created a custom HttpModule for managing the security of my application. in "Init" sub, I regsiter the events doing that : Public Sub Init(ByVal context As System.Web.HttpApplication)...
3
360
by: Samuel | last post by:
I wrote a very simple httpmodule and tried to compile it with no success. This is my code: ============== Imports System Imports System.Web Imports Microsoft.VisualBasic NameSpace...
2
4568
by: walter | last post by:
Hi there, I know there is pool of HttpApplications, and for each request coming in, HttpRuntime will dedicate one from pool to serve the request. My questions are : 1. since HttpModule is plug...
1
1881
by: Faraz | last post by:
Hi everyone, I am running into a slight problem. My understanding is that a custom HttpModule will run for every request made to the server, regardless of the extension. I do not experience this...
0
1123
by: mattdev1000 | last post by:
Hello, I have an HttpModule that uses a lazy fetch to a secondary tier for calculating some values (the calculation is can be multisecond in the worse case). The HttpModule spins up a thread to...
3
1828
by: Joseph Geretz | last post by:
I'm implementing a web application whose purpose in life is to act as a data conduit. Data is posted to my Web app in XML format, my application examines the data and forwards it onward by posting...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.