Question

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!

Was it helpful?

Solution

I should have spent a few more minutes trying assembly names, namespaces and class names. I tried again today and this combination worked where nothing else would.

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

I thought I had tried this combination but apparently I didn't.

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