简体   繁体   中英

How to register a handler in web.config for iis7

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM