-
HttpHandler Not Working
I've never setup a HttpHandler before. What've I done isn't working. Can someone help? The following is what I've done.
1. Created a ClassLibrary project called ImageHandler.
Code:
Imports System
Imports System.Web
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Public Class ImageHandler
Implements IHttpHandler
Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
Try
Dim image As Bitmap = New Bitmap(context.Request.PhysicalPath)
Dim extension As String = Path.GetExtension(context.Request.PhysicalPath).ToLower()
If extension = ".jpg" Then
context.Response.ContentType = "image/jpeg"
image.Save(context.Response.OutputStream, ImageFormat.Jpeg)
ElseIf extension = ",gif" Then
context.Response.ContentType = "image/gif"
image.Save(context.Response.OutputStream, ImageFormat.Gif)
End If
Catch ex As Exception
Dim message As String = "Error: " + ex.Message + vbCrLf + vbCrLf
message += "Stack Trace: " + ex.StackTrace + vbCrLf + vbCrLf
Dim exception As Exception = ex.InnerException
While exception IsNot Nothing
message += "Error: " + exception.Message + vbCrLf + vbCrLf
message += "Stack Trace: " + exception.StackTrace + vbCrLf + vbCrLf
exception = exception.InnerException
End While
Dim log As New EventLog("Application")
log.Source = "InhouseApps"
log.WriteEntry("This is a simple event log entry")
End Try
End Sub
End Class
2. Copied the .dll into c:/windows/system32/inetsrv/
3. Added a virtual directory to the web site
I named it HttpHandlerTest.
4. Added .jpg extension to web app.
Went into the properties for the web app. Under Virtual Directory/Application settings I went into Configuration. The added an extension. I selected my dll, typed in .jpg, selected All Verbs (although I think I only need GET).
5. Referenced HttpHandler in my web.config file
Code:
<system.web>
<httpHandlers>
<add verb="*" path="*.jpg" type="ImageHandler.ImageHandler,ImageHandler" />
</httpHandlers>
6. Tested it
When I tested it I don't get any jpg images returned and my code didn't add anything to the event log.
Click here to see the test page, http://itservices.bc3.edu/HttpHandlerTest/testpage.html
Can someone help me get this working?
Thanks,