Custom HTTP Handler in 2.0

B

bryan

If I understand correctly, I can write a custom handler for a given
extension (say .abcd files) by writing a class that implements the
IHttpHandler interface and then registering it in my web config file.
Once I do that, how do I differentiate between different pages with
the abcd extension, and write specific code for each page? (And keep
that code with the page, similar to codebehind.?)

Thanks,
Bryan
 
K

Kevin Spencer

Once you have a handler, the handler is responsible entirely for the
processing. How you handle the different page names is entirely up to you.

From what you're asking, it seems that you don't want a custom HttpHandler;
you just want pages with a .abcd extension to be handled by ASP.Net page
classes. For that, all you need to do is configure IIS to hand off requests
for pages with that extension to the ASP.Net ISAPI.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
T

tdavisjr

After you register the .abcd extension in IIS by configurating it to be
handled by aspnet_isapi.dll, you really don't have to write physical
files with .abcd extension. All your files would be .cs or .vb files
and they would have their own class names.

To really answer your question, you would probably have to create a
Page Handler Factory of classes. Probably utilize IHttpHandlerFactory.

See
http://msdn.microsoft.com/library/d...lrfsystemwebihttphandlerfactoryclasstopic.asp
 
J

Juan T. Llibre

If all Bryan wants to do is add a specific extension ( .abcd ) to the
pages which are served by his server, he can use this in web.config:

<httpHandlers>
<add verb="GET, HEAD, POST, DEBUG" path="*.abcd" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
<compilation>
<buildProviders>
<add extension=".abcd" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>

and map the extension .abcd to aspnet_isapi.dll in the
Application's configuration section in the Internet Service Manager.

That will cause ASP.NET to process the .abcd extension
in the exact same way it processes files with the .aspx extension.

That means that, if the page is named "whatever.abcd", the corresponding
codebehind pages would need to be named : "whatever.abcd.cs" or "whatever.abcd.vb".





Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 
T

tdavisjr

Kevin said:
From what you're asking, it seems that you don't want a custom HttpHandler;
you just want pages with a .abcd extension to be handled by ASP.Net page
classes. For that, all you need to do is configure IIS to hand off requests
for pages with that extension to the ASP.Net ISAPI.


Doing it this way is fine. But, you would loose all IDE features that
VS.2005 provides since its doesn't understand the .abcd extension. But
if you write all your pages as .cs class files that inherit from
IHttpHandler then you can get the intellisense and other IDE
enhancements.
 
J

Juan T. Llibre

I should have added that's an ASP.NET 2.0-specific solution.
It's a bit simpler in ASP.NET 1.1.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
If all Bryan wants to do is add a specific extension ( .abcd ) to the
pages which are served by his server, he can use this in web.config:

<httpHandlers>
<add verb="GET, HEAD, POST, DEBUG" path="*.abcd" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
<compilation>
<buildProviders>
<add extension=".abcd" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>

and map the extension .abcd to aspnet_isapi.dll in the
Application's configuration section in the Internet Service Manager.

That will cause ASP.NET to process the .abcd extension
in the exact same way it processes files with the .aspx extension.

That means that, if the page is named "whatever.abcd", the corresponding
codebehind pages would need to be named : "whatever.abcd.cs" or "whatever.abcd.vb".





Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top