开发者

Why my HttpHandler is ignored?

In an ASP.NET application, I need to do some changes on every CSS file sent.

So I created an HttpHandler (inside the app itself), added:

<add verb="*" path="*.css" type="MyWebsite.CssTestHandler,MyWebsite"/>

to Web.config in system.web/httpHandlers and modified the handler like this:

public void ProcessRequest(HttpContext context)
{
    context.Response.Clear();
    context.Response.Write("Hello World");
    context.Response.End();
}

But CSS files are still just like they were before, so the handler is just开发者_如何学运维 ignored.

What I'm doing wrong?


You need to setup a wildcard map in IIS, see the following link:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

This will cause the request for the CSS file to be served by ASP.NET rather than just IIS.

If the application serves very high traffic, consider setting this mapping for .css files only, or even better change the CSS data in the page rather than changing the file.


Check this page for instructions on all 3 cases of IIS version (6, 7 Classic pipeline and 7 Integrated pipeline): http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/

According to it, in case of Integrated pipeline, you need to add the following config parameter:

runAllManagedModulesForAllRequests="True"


The App ignores your CSS files because IIS ignores CSS files.

It's not mapped to an executable in IIS. alt text http://www.fastpics.net/sharepics/imih41904722.jpg

Try adding the .css extension and map it to the .NET dll.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜