Wednesday, February 04, 2009

ASP.NET Variables in link - Solved

When I implemented an anti-cache function for my website i discovered that ASP.NET somehow parses <link> tags and makes it impossible to add parameters to the url.

I pass an version number to the url so that I can force new loads of the js and CSS, like this:


<script src="/script/portal.js?v=<%=ScriptVersion%>" type="text/javascript"></script>
<link href="/css/portal.css?v=<%=ScriptVersion%>" rel="stylesheet" type="text/css" media="screen" /> <!-- does not work -->


Somehow ASP.NET parse the <link> tag and create this ugly code:


<link href="/css/portal.css?v=&lt;%=ScriptVersion%&gt;" rel="stylesheet" type="text/css" media="screen" /> <!-- does not work -->


The only solution for this was to include CSS like this;


<style type="text/css" media="screen">
@import "/css/portal.css?v=<%=ScriptVersion%>";
</style>



JavaScript includes works perfect, it's just the css links that is parsed :/

No comments: