When I add an HTTP handler:
<add verb="*" path="*test.aspx" type="Handler"/>
With the class:
using System;
using System.Web;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get { return false; }
}
}
My ASP.NET application dies with the error "Could not load type 'Handler'." when I try to access http://localhost:port/mysite/this-is-a-test.aspx.
I thought maybe it was a namespace issue, so I tried what follows, but got the same "Could not load type 'Test.Handler'." error.
<add verb="*" path="*test.aspx" type="Test.Handler, Test"/>
With the class:
using System;
using System.Web;
namespace Test
{
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get { return false; }
}
}
}
I knew I was getting rusty with ASP.NET, but I'm without a clue on this one.
I guess you are using a web site project in contrast of web application project. In this case you need to put the code behind file of your handler (Handler.cs) in the special App_Code folder. The markup file (Handler.ashx) may be at the root of your site:
<%@ WebHandler Language="C#" Class="Handler" CodeBehind="Handler.cs" %>
Then you can directly declare your handler in web.config:
<add verb="*" path="*test.aspx" type="Handler"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With