开发者

How to call a local HTTP Handler

I've got a HTTPHandler which returns either an image or some text and want to call it from the local web-app.

One way to do it would be to create a WebClient and point it at the handler and download the data that way but this will have problems when authentication is turned on in production and also doesn't seem that efficient. Is there a better way to do this?

The reason I'm trying to do this is that I have a page which injects content from other sources into panels, some of the resou开发者_开发问答rces are local (to the web-app) and others are remote, I wanted one solution to cover every possibility so I can change the source fairly easily.


One of the simplest way is to link the content i.e. use html elements such as image, Iframe and point their source to the handler in question. It will work with local as well as remote handlers as long as URLs are accessible from client/browser.

If you must get the content for some kind of processing etc, then you may use WebClient to download the content - it anyway support HTTP based authentication schemes (including windows/integrated authentication) so it shouldn't be an issue.

If you want to optimize the process for local handlers then you probably need to abstract the interface for content provider - you can have two implementations (one that use WebClient to get remote content and other that will probably use the native API of local handler class directly to get the content).


  1. Extract the code from your handler to a separate assembly
  2. Reference this assembly in the project that has HTTP Handler and make the handler just call your shared code
  3. Reference this assembly in your web app project.

You might want to create a provider for your web app that will either use an assembly in-proc or go to a remote site.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜