URL参数css文件添加在ASP文件夹主题 [英] Add url parameter to css file in asp themes folder

查看:222
本文介绍了URL参数css文件添加在ASP文件夹主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一下code,随着js文件版本帮助的。本质上,它打转当前的脚本经理和追加的文件的MD5哈希的JavaScript文件的路径。因此,

I have written a bit of code that helps with versioning of js files. Essentially it spins around the current script manager and appends the javascript file path with an md5 hash of the file. So

<script src="../Javascript/Navigation.js" type="text/javascript"></script>

变为

<script src="../Javascript/Navigation.js?md5=70D2B4D1F236C7E340D9152B9E4102C3" type="text/javascript"></script>

我觉得这是一个相当普遍的事(或它的变体)。我所努力做的就是拿起css文件中的文件夹App_Themes文件和做同样的。

I think this is a fairly common thing to do (or variants of it). What I am struggling to do is pick up the css files in the app_themes folder and do the same.

我如何获得和更改CSS链接?

How do I get in and change the css links?

推荐答案

您可以使用控制适配器整齐地注入这种行为到页面如下:

You can use a control adapter to neatly inject this behavior into the page as follows:

public class PageAdapter : System.Web.UI.Adapters.PageAdapter
{
    protected override void OnPreRender(System.EventArgs e)
    {
        foreach (var link in Page.Header.Controls.OfType<HtmlLink>().ToList())
            if (link.Attributes["type"].Equals("text/css", StringComparison.OrdinalIgnoreCase))
                if (link.Attributes["href"].Contains("/App_Themes/{0}/".Fill(Page.Theme), StringComparison.OrdinalIgnoreCase))
                   /* process link */

        base.OnPreRender(e);
    }
}

您可以通过保存以下为 *浏览器在 App_Browsers文件文件夹文件将其插入

You can plug it in by saving the following as a *.browser file in the App_Browsers folder:

<browsers>
  <browser refID="Default">
    <controlAdapters>
      <adapter controlType="System.Web.UI.Page"
               adapterType="PageAdapter" />
    </controlAdapters>
  </browser>
</browsers>

总体来说,我觉得控制适配器是注射行为纳入控制/页面生命周期的强大AOP样的机制;他们几乎完全忽视赞成传统的子类的。

Overall, I think Control Adapters are a powerful AOP-like mechanism for injecting behavior into control/page life-cycles; they are almost entirely ignored in favor of traditional sub-classing.

这篇关于URL参数css文件添加在ASP文件夹主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆