I have a .aspx page which I want the browser to treat like a regular .css file. The code in the .aspx looks like this:
<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server" type="text/C#">
protected void Page_Init(object sender, EventArgs e)
{
Response.ContentType = "text/css";
}
</script>
@import url(<%= "myCss.css" %>)
This works fine in Chrome, Firefox 3.5.5, and IE8 except when IE8 is running in Compatability View when the CSS does not appear to be affecting the page at all - i.e. I see my web page with no styles applied.
How do I serve CSS from .aspx in a way that will work across all (most) browsers?
EDIT: When I change the actual CSS being served from
@import url(<%= "myCss.css" %>)
to
div { background-color: yellow; }
IE8 Compatability view seems to work perfectly.
EDIT: After dismantling and rebuilding my page a couple of times, everything seems to work but I'm still not sure why it works. I'm going to mark Dmitriy's answer as correct anyway because I've changed my code to his much nicer version.