1

I can append a token to my script references like this:

<script type="text/javascript" src="/Some.js?<%= Html.GetToken() %>"></script>

... and this works fine. But, if I try to append the same token the same way to a CSS file reference:

<link rel="stylesheet" type="text/css" href="/Some.css?<%= Html.GetToken() %>" />

... the IIS generates the following markup:

<link rel="stylesheet" type="text/css" href="/Some.css?&lt;%= Html.GetToken() %>" />

I know I'm missing something super simple but I cannot see what exactly. Thanks in advance for any help!

2 Answers2

3

This happens if your <head> section has runat="server". If you can live without it (in ASP.NET MVC you usually can) try it this way.

If not, add or modify the CSS link in your view's Page_Load. If that sounds awful to you, then removing runat="server" should be working :)

orip
  • 73,323
  • 21
  • 116
  • 148
  • 2
    Thanks! That was it - runat in the head. Very strange, though. Looks like a bug in MS code, isn't it? –  Aug 17 '11 at 14:37
  • Dunno, in my experience WebForms templating has many unexpected behaviors in order to enable their complex features. – orip Aug 17 '11 at 14:40
  • runat="server" tells asp.net that the tag is to be a server-side control. At that point you can no longer treat it like a literal and insert your inline values. – agradl Aug 17 '11 at 14:47
  • @shiznit123 - yeah, but why does it work with a ` – orip Aug 17 '11 at 14:50
0

There a trick you can use for auto versioning.

Check out the post here:

Auto-versioning in ASP.NET MVC for CSS / JS Files?

Community
  • 1
  • 1
Michael D. Irizarry
  • 6,186
  • 5
  • 30
  • 35