开发者

ASP.NET MVC: how to append a token to CSS URL properly?

开发者 https://www.devze.com 2023-03-28 22:38 出处:网络
I can append a token to my script references like this: <script type=\"text/javascript\" src=\"/Some.js?<%= Html.GetToken() %>\"></script>

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 miss开发者_运维技巧ing something super simple but I cannot see what exactly. Thanks in advance for any help!


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 :)


There a trick you can use for auto versioning.

Check out the post here:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消