开发者

Using custom httphandler from a custom assembly

Is it possible to register a custom httphandler in a stand alone assembly? I'm writing a control toolkit that uses httphandlers to perform AJAX and I would like to make the use of the toolkit as low frictio开发者_开发技巧n for the web developers as possible. There will be quite a few handlers and I dont want the developer to have to register them all in the web.config.

Can they be referenced directly in the assembly?


I'm not sure if that is possible, but it certainly strikes me as the wrong approach.

If you are developing your own toolkit then you could instead make a http handler that identifies and calls other http handlers based on whatever logic you want:

public class MyToolkitHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        IHttpHandler handler = Toolkit.GetHandler();
        if (handler != null)
        {
            handler.ProcessRequest(context);
        }
    }
}

This would mean that you only need to register the one handler in your web.config.


Yes, in the:

<system.web>
   <httpHandlers>
   </httpHandlers>
<system.web>
<system.webServer>
   <handlers>
   </handlers>
<system.webServer>

Sections; just supply the fully-quantified name as the type. You have to do this registration; otherwise, you can't use them in the app. A handler has to be mapped to a URL or a handler factory to a file extension.

HTH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜