Question

I had to 301 redirect some htm pages. I am trying to do it via HttpHandler. This website dosen't use any namespace. I created a test handler as follows:

<%@ WebHandler Language="C#" Class="htmlhandler" %>

using System;
using System.Web;

public class htmlhandler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        string url = HttpContext.Current.Request.Url.AbsoluteUri;
        context.Response.ContentType = "text/plain";
        context.Response.Write(url);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

In Web.config I tried to register the handler as follows:

<httpHandlers>
  <add verb="*" path="*.htm" type="htmlhandler"/>
</httpHandlers>

But I am getting the following error:

Parser Error Message: Could not load file or assembly 'htmlhandler' or one of its dependencies. The system cannot find the file specified.

Please help. My handler is placed in App_Code folder but still the server is unable to find it.

Was it helpful?

Solution

Try using <add verb="*" path="*.htm" type="htmlhandler, assemblyName"/>.

Also <system.webServer> is valid only if you running the App Pool in Integrated mode. Check if you are running the App Pool in Integrated or Classic mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top