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.
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.