473,796 Members | 2,429 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.Visua lBasic

NameSpace myErrorHandler

Public Class myExceptionHand ler
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.GetL astError()

Dim errorInfo as string = _
"<br>Offend ing URL: " & ctx.Request.Url .ToString() & _
"<br>Source : " & exception.Sourc e & _
"<br>Messag e: " & exception.Messa ge & _
"<br>Stack trace: " & exception.Stack Trace

ctx.Response.Wr ite (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\Micro soft.NET\Framew ork\v1.1.4322
to compile the code:

vbc /t:library /r:System.dll,Sy stem.web.dll PGDErrorHandler .vb
Jul 22 '05 #1
3 2214
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 misunderstandin g, 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.IHtt pModule.Init
AddHandler objApp.Error, AddressOf Me.OnError
End Sub

Public Sub Dispose() Implements System.Web.IHtt pModule.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.Cl earContent()

ctx.Response.Wr ite( "<font size='30' color='red'>unh andled error
occured</font>")

ctx.Response.En d()

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: AcWCCRfXvfZq231 RTSGw1n1egq22Aw ==
| X-WBNR-Posting-Host: 64.180.224.155
| From: =?Utf-8?B?U2FtdWVs?= <pr********@nos pam.nospam>
| References: <B6************ *************** *******@microso ft.com>
<Fv************ *@TK2MSFTNGXA01 .phx.gbl>
| Subject: RE: question regarding this httpmodule
| Date: Wed, 6 Jul 2005 02:00:01 -0700
| Lines: 6
| Message-ID: <D4************ *************** *******@microso ft.com>
| 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.publi c.dotnet.genera l
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.genera l:45503
| X-Tomcat-NG: microsoft.publi c.dotnet.genera l
|
| 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
2580
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 http://my_machine_name/site) show problems when refresh the page. I guess some kind of javascript problems with the postback methods. Someone has any idea how can i fix it? Thanks
4
3912
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 database. For example, when a page set values to Session object such as Session("somevar")=1 then I want my HttpModule to get notified and store the value into the external database. The same for "getting" the variable, I want my own...
5
1413
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. http://www.abc.com/joe.block/index.html will actully be mapped to c:\root\docs\somedir\joeblocks\index.html for this HttpModule to take effect I have done the wildcard mapping on main folder but I want to allow to have classic asp pages in one of
2
2144
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) Implements IHttpModule.Init httpApp = context
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 myErrorHandler
2
4587
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 into the process, does each instance of HttpApplication keep its own set of HttpModule instance or HttpModules are shared among all HttpApplication instances? 2. In case of HttpApplication keep its own set of HttpModule, does the HttpModule...
1
1903
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 behavior. My module only runs for the extensions handled by the aspnet_isapi.dll. Here are my sequence of steps: 1) Create the HttpModule 2) Compile and drop dll in the webApp bin directory.
0
1135
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 listen for a response from this 2nd tier and will cache the results in a large table for service subsequent requests. I notice that the HttpModule will unload from time to time and realize this is normal behavior but was wondering if there was...
3
1839
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 it to the appropriate upstream server. Since transaction processing is largely identical regardless of the transaction details (these will be handled by an upstream sever) I'm thinking of implementing my application as an HttpModule. But I'm...
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.