[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-05-30
17
Medium Priority
?
1,021 Views
Last Modified: 2008-01-16
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
0
Comment
Question by:AGBrown
  • 10
  • 7
17 Comments
 
LVL 12

Author Comment

by:AGBrown
ID: 16789292
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.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16789555
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
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16789591
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Author Comment

by:AGBrown
ID: 16789597
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;
            }
        }

    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16789636
I apologize for still not understanding what dynamic CSS can do for you that themes/skins can't.

Bob
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16789754
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16789800
Good enough ;)

Where is the HttpHandler located?  bin\ folder?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16789814
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
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16789912
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
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16789924
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!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16790018
Where did you copy the StyleSheetHandler.dll?  It should be in the \bin folder.

Bob
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16790094
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.
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16790427
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
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16790532
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
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16790562
Andy,

Here is a possible explanation:

StaticFileHandler Behavior Issues
http://www.agileprogrammer.com/dotnetguy/archive/2003/05/04/4550.aspx

<httpHandlers>
<!-- Content handlers -->
<add verb="GET,HEAD" path="*.css" type="System.Web.StaticFileHandler" />
<add verb="GET,HEAD" path="*.js" type="System.Web.StaticFileHandler" />
<add verb="GET,HEAD" path="*.jpg" type="System.Web.StaticFileHandler" />
<add verb="GET,HEAD" path="*.gif" type="System.Web.StaticFileHandler" />
<add verb="GET,HEAD" path="*.html" type="System.Web.StaticFileHandler" />
</httpHandlers>

I don't think this is what you want, though.

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16790576
Ok, I was wrong, that was what you needed.

Bob
0
 
LVL 12

Author Comment

by:AGBrown
ID: 16790694
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question