Groups > Asp .Net > HttpHandlers and HttpModules > Re: Css HttpHandler




Css HttpHandler

Css HttpHandler
Sat, 29 Mar 2008 00:07:35 +000
Hello,

 I'm using a HttpHandler for all css requests so I can modify the contents of
the css file dinamically based on the content from the database. The web.config
is straightforward:<httpHandlers>

<addverb="*"path="*.css"type="CssHandler"
/>

</httpHandlers>

In the CssHandler class form App_code folder I'm doing the processing of the css
and then write it to the response. This approach works perfectly on IE but
strangely not in firefox.  In my master page I`m using the
css:<linkhref="css/default.css"rel="stylesheet"type="
;text/css"/>

  In the debug mode I see that both IE and firefox receive the css content. If I
just remove the handler from web.config the pages works good in firefox too. I
don't see why the handler doesn't work in firefox.

HttpHandler:

 

1    public void ProcessRequest(System.Web.HttpContext context)
2        {
3    // Get the physical path of the file being processed4    string File =
context.Request.PhysicalPath;
5    6    // Open the file, read the contents and replace the variables7   
using (System.IO.StreamReader reader = new System.IO.StreamReader(File))
8            {
9    string css = reader.ReadToEnd();
10               css = css.Replace("#img2#", "../images/" +
"img02.jpg");
11               css = css.Replace("#img3#", "../images/" +
"img03.jpg");
12               context.Response.Write(css);
13           }
14       }


Thanks
Post Reply
Re: Css HttpHandler
Sat, 29 Mar 2008 02:47:21 +000
You could try adding a content type header so that Firefox will know that it's
dealing with css.




 context.Response.ContentType="text/css";
Post Reply
Re: Css HttpHandler
Sat, 29 Mar 2008 09:24:09 +000
Thank you very much, that works.
Post Reply
about | contact