HttpHandler 101 FAIL
When I add an HTTP handler:
<add verb="*" path="*test.aspx" type="Handler"/> With 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; } } } ASP.NET application dies with the error "Failed to load the type" Handler. " when I try to access http: // localhost: port / mysite / this-is-a-test.aspx .
I thought it was a problem with the namespace, so I tried what followed, but got the same "Test.Handler type failed to load." mistake.
<add verb="*" path="*test.aspx" type="Test.Handler, Test"/> With 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 that I am rusty with ASP.NET, but I do not know how to do this.
I assume that you are using a website project as opposed to a web application project. In this case, you need to place the code behind the file of your handler (Handler.cs) in a special App_Code folder. The markup file (Handler.ashx) may be located at the root of your site:
<%@ WebHandler Language="C#" Class="Handler" CodeBehind="Handler.cs" %> Then you can directly declare your handler in the web.config file:
<add verb="*" path="*test.aspx" type="Handler"/>