473,473 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Create 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 2178
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
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
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
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
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
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
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
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
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.