Link to home
Start Free TrialLog in
Avatar of AGBrown
AGBrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

HttpHandler for stylesheets not working on windows server 2003/IIS 6.0 (.NET 2.0)

I have developed a (simple) test httphandler for my stylesheets. It works fine in an application in a virtual directory on IIS 5.1 on the development Xp SP2 machine, but when I deploy it to the server, it stops working and I just get a 404 for any stylesheet that I request. I have set the server virtual directory up, as far as I can see, absolutely identically. This is what I've covered so far:
-There are no error messages being given, I just get a 404.
-There are no event log messages being given.
-I have registered the .css extension has to be handled by the .NET framework under the properties/virtual directory/configuration using:
    +c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
    +for GET,HEAD,POST,DEBUG
    +with "script engine" checked,
    +and "verify" not checked (as some css files do not exist on disk).
-The web.config contains the appropriate httpHandlers key:

            <httpHandlers>
                  <add verb="*" path="css*.css" type="StyleSheetHandler, App_Code"/> <!-- removing ', App_Code' appears to make no difference -->
            </httpHandlers>
-The web.config in the directory that the style sheets are "in" allows all users and anonymous users to access the style sheets:
      <?xml version="1.0" encoding="utf-8"?>
      <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
            <system.web>
                  <authorization>
                        <allow users="*,?" />
                  </authorization>
            </system.web>
      </configuration>
-A test deploy from VS2005 to another VDir on IIS 5.1 also works fine
-Copying that test deploy (straight drag and drop to the server) still does not work.

Any ideas?

Andy
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I've narrowed the problem down further, it seems that style sheets that match the httpHandler are being server (e.g. css1.css), but that style sheets that exist on disk and don't match the httpHandler are not being served (e.g. test.css). This is not the case on XP SP2/IIS 5.1, so what do I have to do to pick up style sheets on disk that don't match the style sheet httphandler? I would prefer not to have to write another style sheet handler or include code to return the files from disk if possible.
Avatar of Bob Learned
I am trying to figure out what this handler does for you, but I can't see it.  How does this help you?  What are you trying to do that can't be handled any other way?

Bob
Avatar of AGBrown

ASKER

Hi Bob,

My http handler (see code below for a testable example) creates style sheets by substituting different things into a template based on the user's choices. In addition, there are also style sheets which are static and don't require substitution, so I don't do those through the httpHandler, instead they come from files stored in the web directory. As an example, a dynamic (css123.css) style sheet may contain an @import for a static stylesheet such as:
@import url(test.css);

The thing that has me stumped is that this works on IIS 5.1, and not on IIS 6.0.

I'll admit, I'll be happy with a workaround, but I'd quite like to know why it isn't working on IIS 6.0 as well.

Andy
Avatar of AGBrown

ASKER

Here's the example code for the httpHandler:
    public class StyleSheetHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/css";
            context.Response.Write("@import url(test.css);");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
I apologize for still not understanding what dynamic CSS can do for you that themes/skins can't.

Bob
Avatar of AGBrown

ASKER

Bob,

Would you be willing to take the css vs. themes topic up in a seperate question if I post one? I'd like to know more about themes, and see if they would fit this problem, but try and get a short term fix to this problem as well.

Andy
Good enough ;)

Where is the HttpHandler located?  bin\ folder?

Bob
I found this article, from Micro$oft, and I am trying to see where the problem lies, because I haven't used 6.0 enough to know the exact answer:

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/784eeb32-d781-4917-95b3-34f302a81680.mspx?mfr=true

Bob
Avatar of AGBrown

ASKER

Here's the relevant structure:
App root
    App_Code
        StyleSheetHandler.cs
    ClientStyles
        test.css
    web.config

So the httpHandler is part of the application's App_Code assembly. I'm deploying the application with "allow this precompiled site to be updateable" and "use fixed naming and single page assemblies".

I've just looked over that article, and my settings seem to match up ok:
<add verb="*" path="css*.css" type="StyleSheetHandler, App_Code"/>
and the css extension is mapped to the .NET 2.0 aspnet_isapi.dll. Testing this by requesting http://localhost/testvdir/ClientStyles/css1.css returns a css file so the httpHandler itself is working.

But http://localhost/testvdir/ClientStyles/test.css still returns an error, so the file that is not meant to be handled by the httpHandler is not being served. The one thing that might help a little is that, by bringing up fiddler, the error is not actually a 404, its just not returning at all. I'll turn tracing on on the application and see what comes up...

Andy
Avatar of AGBrown

ASKER

And when I've got a second between typing, testing and fielding calls from my colleague who's also trying to fix this, I'll put up the themes vs. css question and link it from here!
Where did you copy the StyleSheetHandler.dll?  It should be in the \bin folder.

Bob
Avatar of AGBrown

ASKER

I see what you're asking, I wasn't clear enough on that one. There is no StyleSheetHandler.dll - the code is in the App_Code directory, so it's compiled into the App_Code.dll which is then in the bin directory as part of the deployment from VS2005.

I turned on and looked at the trace.axd on IIS 6.0: A single request on IIS 6.0 for test.css creates 101 (actually 101) trace log events. Each of which has a status of 200 - i.e., it should be returning with no problems. The physical path that it is transating is correct as well.
Avatar of AGBrown

ASKER

It looks like this is describing my situation:
http://msdn.microsoft.com/netframework/programming/breakingchanges/runtime/aspnet.aspx
-"Static file no longer served when mapped to aspnet isapi"
-"Static files are no longer served when mapped to isapi"

but I can't work out what they mean by:
"Create specific mappings in ASP.NET handler configuration to StaticFileHandler for all specific mappings in IIS6 scriptmaps."
in terms of what the "StaticFileHandler" is

Andy
Avatar of AGBrown

ASKER

Fixed:

http://support.microsoft.com/?kbid=909641

with the addition of an extra httpHandler:

      <httpHandlers>
            <add verb="*" path="css*.css" type="StyleSheetHandler, App_Code"/>
            <add verb="*" path="*.css" type="System.Web.StaticFileHandler"/>
      </httpHandlers>

That makes IIS 6.0 serve css files with "css*.css" filenames through the stylesheethandler, and if the files don't match that name, then it will server them via the staticfilehandler as per usual.

Andy
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I was wrong, that was what you needed.

Bob
Avatar of AGBrown

ASKER

lol.

Thanks Bob. You got there just as we did, so you get the points.

The worst thing is that I had done due-diligence on all the 1.1 to 2.0 breaking changes, but because of the IIS5.1 works/IIS 6.0 doesn't work behaviour, I hadn't connected the dots.

Here's the link to the themes vs css question. I'd like to know what you think. I've put the caveats in there for other people's benefit, not yours ;). The number of "original" articles I have found on the web that just cut and paste the "Themes vs. Cascading Style Sheets" section out of the MSDN ASP.NET Themes and Skins Overview is ridiculous.
http:Q_21868235.html

Andy