Add httphanlder

  • Thread starter Thread starter Guoqi Zheng
  • Start date Start date
G

Guoqi Zheng

Sir,

I am very new to ASP.NET.

Trying to create a Httphanlder myself.

1. I create a httphandler called qqweb.vb and put it under /bin folder.
qqweb has namespace qqweb and class qqhandler
2. I add the following into web.config.
<httpModules>
<add name="HTTPHandler" type="qqweb.qqhanlder, qqweb" />
</httpModules>

3. It always return an error with file or assembly not found.

What should I do? I am using web matrix. Can I use a .vb or .ashx instead of
..dll file?

I am tried to compile file under web matrix using an add in. But it always
give an error like ": Name 'InStr' is not declared."


What should I do?

Thanks in advanced for your help!!!
 
Hi,

if you create HttpHandler, you need to register it within <httpHandlers>
element. <httpModules> is, as its name states, for HTTP modules which are
different concept from HTTP handlers. You need also to register the
extension you use for the HTTP handler in IIS to aspnet_isapi.dll so that
request for the extension is forwarded to ASP.NET

So which one you are really trying to create, HTTP module or HTTP handler?
HttpHandler is for processing the request, HTTP modules for doing work
before or after the handler has done its job (pre- and postprocessing the
request).
 
Thanks a lot for your quick reply. I think what I am doing is httphandler.

I am not really sure. I am using it to create search engine friendly URL.

Please see my code below.

I tried to register it by <httpHandlers>, but it seems that asp.net can not
recognize <httpHandlers>.


Imports System
Imports System.Web
Imports system.Configuration
Imports system.Text

Namespace qqweb

Public Class HTTPHandler
Implements IHttpModule
Public Sub Init(ByVal app As HttpApplication) Implements
IHttpModule.Init
AddHandler app.BeginRequest, AddressOf Me.OnBeginRequest
End Sub
Public Sub Dispose() Implements IHttpModule.Dispose
End Sub

Public Delegate Sub MyEventHandler(ByVal s As Object, ByVal e As
EventArgs)
Public Event MyEvent As MyEventHandler

Public Sub OnBeginRequest(ByVal s As Object, ByVal e As EventArgs)
Dim objHttpApplication As HttpApplication = CType(s, HttpApplication)
'check for a director path being sent instead of the query string.
Dim sURL As String = objHttpApplication.Request.Url.ToString.ToLower
If InStr(sURL, "/product/") <> 0 Then
'now we'll replace the paths with the appropriate query strings.
Dim sNewURL As String = Replace(sURL, "/Product/", "?product="
' sNewURL = Replace(sNewURL, "/site/", "&site=")
'now we'll rewrite the directory path and send our script a query
string
'that it can deal with.
objHttpApplication.Context.RewritePath("~/product.aspx" & sNewURL)
End If
End Sub

End Class
End Namespace


--
Met vriendelijke groet,

Guoqi Zheng
Tel: +31 (0) 23 5343545
http://www.meetholland.com
 
It is HTTP module as you implement IHttpModule interface. OK, you had error
with InStr, try importing Microsoft.VisualBasic namespace as I believe InStr
function is for backward compatibility.
 
Back
Top