0

I recently decided that I would write a custom ASP.NET web control to take a preview of a website and display it as an image. I found various methods of doing this on the internet and took my favorite parts from each.

The first revision of the web control worked well enough but the previews weren't being generated asynchronously so the use of the control was frustrating because of load times. I wrote another revision of code to generate the previews in different requests (using a handler) and this worked well also.

My third revision was to write a custom control that used the handler so that I could get the convenience of the control and the delayed loading of the handler. This worked well in its own project. Where it became complicated was when I tried to register the handler from the control library project in a different website project.

First off, am I going about this the right way? It seemed like a great idea until I tried to register the handler. Using the control is easy enough.

Second, if this is the correct method of doing this how do I register this handler? Inside the web applications web.config I have tried various flavors of class names and namespaces but I always get a 404 when the control tries to load the image from the handler.

Here's what I have right now to get an idea:

<add verb="GET" name="ThumbnailHandler" path="GenerateWebsitePreview.ashx" type="HandlerGenerateWebsitePreview, ThumbnailControl"/>

Name: This doesn't matter as far as I can tell. It's not required in any of the documentation I've read and is almost never mentioned. Path: This is the path/url I want to invoke the handler. This does not exist in the web application project obviously nor should it. I want it to reuse the one from the library. With handlers you can use whatever path you want though. Type: HandlerGenerateWebsitePreview is the name of the class that implements IHttpHandler. ThumbnailControl is the namespace that this class sits in.

The web application already has a project reference to the library project that contains the custom control and the custom handler. This reference is known to be working because the custom controls are found and rendered.

How do you reuse custom handlers if you can't register a handler from another project? The "assembly" attribute isn't allowed in the "add" tag like it is when you register the custom control.

Thanks in advance!

4

1 回答 1

0

我应该再花几分钟尝试程序集名称、名称空间和类名。我今天又试了一次,这种组合在其他任何地方都不起作用。

<add verb="GET" name="Name" path="path.path" type="Namespace.ClassName, AssemblyName"/>

我以为我已经尝试过这种组合,但显然我没有。

于 2013-10-17T05:58:09.073 回答