I have set up an HttpHandler
for *css
to do some simple parsing:
<handlers>
<add name="CssHandler" verb="*" path="*.css"
type="MyApp.CssProcessor,MyApp.Assembly"/>
</handlers>
All was well until I added a resource that loads a css file dynamically, e.g.
<link rel="stylesheet" type="text/css" href="/loader.ashx/module.resource.css" >
To my surprise, things went horribly wrong. The custom http handler intercepts this, but since it's designed to just load files from the file system, it doesn't work. I realize that, technically, it matches a pattern *.css
but that seems an odd behaviour, since the actual resource being requested from the web server is *.ashx
and the css is only after the file path, as a parameter.
Is it possible to make the filter for a handler only apply to the actual server resource name?
Alternatively (and actually I'd like to know how to do this anyway) -- what I would really rather be doing is intercepting the output from the default css handler. That is, rather than having all my own code to actually load files from the file system in my CSS handler, it seems it would be far simpler to just take the response from the default handler and filter it. Which w开发者_高级运维ould have worked properly in this situation.
Finally, in either case, I'd much rather be filtering on resource MIME type text/css
rather than intercepting requests by name, since what I really want to do is filter any CSS (rather than anything that happens to be named "*.css"). Any pointers on how to do this?
You could... 1) Modify your handler to check if a file exists. 2) Use an HttpModule to intercept the response. Not sure exactly what you're doing in this scenario, but actually modifying the output can get tricky. 3) Modify the argument being passed to loader.ashx to not end with .css (that's kind of hacky) 4) Try using a "?" as the separator between loader.ashx and the argument, since there are other requests (.axd) that often use querystring parameters and still work properly.
精彩评论