Serve javascript file via http Handler

前端 未结 1 1717
你的背包
你的背包 2021-01-26 02:45

I\'ve written a HTTP Handler that outputs content depending on values passed to the handler. I am trying to extend it so that it outputs flash aswell, however to do so I need to

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 03:17

    You get InvalidCastException because your are trying to convert your current handler (ashx) to the page type.

    I am not certain what you want to return in flash case - I am assuming that you probably want to return an html page with flash object embedded within and with js file included in header. So you need to emit such html where you would include link to the js file. Now, as you don't have js on file system, your link should point to yet another handler that would extract the js code from embedded assembly and return it. Luckily such handler is already available (WebResourceLoader) and you can use it below to get the needed url:

    (new Page()).ClientScript.GetWebResourceUrl(typeof(MyAssembly.Load), "MyResourceAssembly.swfobject.js");
    

    Trick is that because you don't have client script manager in generic handler, you simply create a new page instance and use that.

    0 讨论(0)
提交回复
热议问题