469,613 Members | 1,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

HTTP handlers WEB.CONFIG syntax, please !

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("ProductNa me"))
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\ProductsHand ler\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.
Nov 19 '05 #1
3 1798
Sorry, in the previous post I have misspelled the address I'm using - it
should be:
http://localhost/aspnetprojects/vsne.../Product1.aspx
instead of
http:\\localhost\aspnetprojects\vsnet\ProductsHand ler\Product1.aspx
Nov 19 '05 #2
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
--
MY ASP.Net tutorials
http://www.openmymind.net/
"msnews.microsoft.com" <RE***********************@yahoo.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
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("ProductNa me"))
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\ProductsHand ler\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.

Nov 19 '05 #3
Thank you, Karl - that was it :-))))) Now I know !

Thanks a lot, once again. Alex.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:et**************@TK2MSFTNGP11.phx.gbl...
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
--
MY ASP.Net tutorials
http://www.openmymind.net/
"msnews.microsoft.com" <RE***********************@yahoo.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
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("ProductNa me"))
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\ProductsHand ler\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.


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jeff Shannon | last post: by
1 post views Thread by R. Raghuraman | last post: by
4 posts views Thread by Nick Gilbert | last post: by
4 posts views Thread by Peter Oliphant | last post: by
2 posts views Thread by Arpan | last post: by
3 posts views Thread by shapper | last post: by
1 post views Thread by hb | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.