Attention: We are retiring the ASP.NET Community Blogs. Learn more >

CSS as a resource file

I just had a friend ask me "can you supply a css page as a streamed binary? like an img from a db?"  I have no idea.  He's thinking it could be a way to dynamically configure the output and solve browser bugs.  I'm not the best at output across differing browsers.  Any ideas?

3 Comments

  • Yep. Simpler than streaming binary, too, since CSS is just text (like HTML). So your css reference is just:



    <link rel='StyleSheet' type='text/css' href='style.aspx'>



    And style.aspx just writes out the appropriate css (from database, css file, etc.). Of course, the reference to style.aspx could be style.aspx?layout=printer&theme=simple.

  • If you go through Rory's archive's at neopoleon.com he threw some code together that accomplishes this task.

  • If you use XHTML doctypes with Mozilla and Mozilla is not given the correct MIME type for the CSS file it will refuse to load it.



    Using an extension other than .css will cause issues in non IE browsers . . .



    the solution is quite simple :o) you just have to inculde the following in the top of your referenced .aspx page:



    <%@ Page Language="C#" ContentType="text/css" ResponseEncoding="iso-8859-1" %>



    without including the ContentType as text/css is just does not work universally.

Comments have been disabled for this content.