Liath
Liath

Reputation: 10191

Detecting the address of an HTTPHandler

I've been working with a HTTPHandler and have a question

If I have a handler A which is registered in web.config to the address A.hdlr I can create a link onto that handler which will go to http://www.mysite.com/A.hdlr - brilliant.

However, if I update my web.config file this address will no longer be valid. Is there a way to detect the currently configured address (and if indeed it is configured) for a handler so that I can update the links accordingly?

Edited to add:

I have currently configured the handler in the

<system.webServer><handlers>

section in the form

<add name="MyHandler" verb="GET" path="MyHandler.hdlr" precondition="integratedMode" type="MyType" />

However I'm open to suggestions - my concern is that referencing "MyHandler.hdlr" directly in code will break if someone updates this config address

Upvotes: 0

Views: 129

Answers (1)

Anand
Anand

Reputation: 14935

what do you mean by update the web config file ? Could you be more clear ?

The only way I know to register a handler is by providing its name or extension in web config file.

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="A.hdlr" 
         type="HandlerA" />
    </httpHandlers>
  </system.web>
</configuration>

It says if resource A.hdlr is requested then it must be handled by HandlerA.ashx.

Okay, Now I have a clear understanding of your concern. Yes, if some body changes it Foo.hdlr then Foo.hdlr resource would be served by MyType handler. But think why anybody would do it ? it's same as writing a code with bad logic.

You could dynamically register a handler by writing a code to modify web.config(but it would restart the App Domain). But that would not guarantee that some body could not modify your dynamic code. Entries in web.config should be dealt carefully.

Upvotes: 1

Related Questions