Add url parameter to css file in asp themes folder

前端 未结 3 2027
抹茶落季
抹茶落季 2021-01-12 20:21

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

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 21:21

    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().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);
        }
    }
    

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

    
      
        
          
        
      
    
    

    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.

提交回复
热议问题