badly stuck creating HTTPHandler

I

Ivonne Riedel

Hi everybody,

I have got a serious problem building an HTTPHandler in codebehind style.
I made the following steps:
Create an ASP .net Website project
Add a generic handler.
Rewrite this "Hello World" item into codebehind style so that the .ashx file
has the only line:
<%@ WebHandler Language="C#" Class="handlerpur"
CodeBehind="handlerpur.ashx.cs" %>

The codebehind file has the rest of the former content of the ashx file:

using System;
using System.Web;

namespace MyNamespace {
public class handlerpur : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}


public bool IsReusable {
get {
return false;
}
}
}
}

Trying to build that I get the error:
Could not create type 'myNameSpace.handlerpur' pointing at the first line of
the ashx file.
I checked permissions, the virtual directory on the iis (it has got an app
name), added things to the web.config, checked the framework version on the
iis.
Am I missing something? I do not have a bin directory in my project and
nothing gets compiled.
I am running WinXp SP2, iis 5.1, ASP.net 2.0.50727.

Any help is greatly appreciated

Thanks

Ivonne.
 
M

Matt Dinovo

Due to the new way ASP.NET projects are compiled, you have one of two
choices here:

First, you could combine everything into your ASHX file (see below):

<%@ WebHandler Language="C#" Class="MyNamespace.handlerpur" %>

using System;
using System.Web;

namespace MyNamespace
{
public class handlerpur : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}


public bool IsReusable
{
get {return false;}
}
}
}

Or you could put the handlerpur.cs file in your App_Code directory so that
it's compiled into the web project DLL and then your ASHX file would only
have the webhandler directive:

<%@ WebHandler Language="C#" Class="MyNamespace.handlerpur" %>

I don't believe that the WebHandler directive allows for 'code behind'
files like a page does.

HTH,

Matt Dinovo
 
I

Ivonne Riedel

You were right Matt, it works. I tried something similar a while ago but
forgot to place the cs in app_code.
Not enought experience with ASP.net assumingly.
 

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,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top