472,783 Members | 974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

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 2128
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.