HTTP handlers WEB.CONFIG syntax, please !

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Hello. I have this code in a project named ProductsHandler:

First, a class called ProductsHandler.vb (this particular code is not
important in this question, because the class is correct - it implements
both IHttpHandler.ProcessRequest and IHttpHandler.IsReusable). Anyway, here
it is:
---------------------------------------------------------------------------------------
Imports System.Data.SqlClient
Imports System.Web
Imports System.Data

Public Class ProductsHandler
Implements IHttpHandler

Public Sub ProcessRequest(ByVal objContext As HttpContext) Implements
IHttpHandler.ProcessRequest

Dim intProductID As Integer
Dim objConn As New SqlConnection()
Dim objCommand As SqlCommand
Dim objDataReader As SqlDataReader
Dim strSelect As String

Try
intProductID = GetProductID(objContext.Request.Path)
strSelect = "Select ProductName, UnitPrice from Products where
ProductID=@ProductID"
objCommand = New SqlCommand(strSelect, objConn)
objCommand.Parameters.Add("@ProductID", intProductID)
objConn.ConnectionString =
ConfigurationSettings.AppSettings("strConn")
objConn.Open()
objDataReader = objCommand.ExecuteReader(CommandBehavior.SingleRow)
If objDataReader.Read Then
objContext.Response.Write("<h2>Product Name: </h2>")
objContext.Response.Write(objDataReader("ProductName"))
objContext.Response.Write("<h2>Product Price: </h2>")
objContext.Response.Write(String.Format("{0,c}",
objDataReader("UnitPrice")))
End If
objConn.Close()
Catch ex As Exception

Finally
objConn.Dispose()
objCommand.Dispose()
End Try
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable

Get
Return True
End Get
End Property

Private Function GetProductID(ByVal strPath As String) As Integer 'Not
finished yet

Return 19
End Function

End Class
---------------------------------------------------------------------------------------
And this is the beginning of my web.config file:
---------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>

<configuration>
<appSettings>
<add key="strConn" value="server=radu;database=workdb;integrated
security=SSPI;"></add>
</appSettings>

<system.web>
<httpHandlers>
<add verb="*" path="*"
type="ProductsHandler,ProductsHandler"></add>
</httpHandlers>

<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to insert debugging symbols (.pdb
information)
into the compiled page. Because this creates a larger file that
executes.....
---------------------------------------------------------------------------------------

I build the project and I see in the folder "C:\Documents and
Settings\Administrator\My Documents\My
Projects\ASPNETProjects\VSNet\ProductsHandler\bin" that there is a file
named ProductsHandler.dll. Correct. I open IIS and I check that my folder
"ASPNETProjects\VSNet\ProductsHandler" is really a virtual folder. It is.
The rights are there and correct, as well.

I expect to open IE and to see the product with ID=19 listed on my page. So
I type the address (it is a correct address !)

http:\\localhost\aspnetprojects\vsnet\ProductsHandler\Product1.aspx

and I get...

Parser Error Message: Could not load type ProductsHandler from assembly
ProductsHandler.

So the question is, please, what's wrong with my "path" in web.config ?

Thank you, Alex.
 
K

Karl Seguin

Hey Alex,
I can give this more of a look, but my initial thought is that your
ProductHandler class is actually within a namespace - namely the name of
your project. However, in your web.config you are simply looking for
ProductHandler....in other words, change your web.config to do
ProjectName.ProductHandler,ProductHandler

Just a quick guess, lemme know...if I'm wrong I'll look more @ it.

Karl
 
M

msnews.microsoft.com

Thank you, Karl - that was it :))))) Now I know !

Thanks a lot, once again. Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top