欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net Bundle功能擴展

 更新時間:2012年11月26日 14:52:32   作者:  
發(fā)現(xiàn)這個東西確實非常實用,且功能強大,BundleTable.Bundles能夠壓縮合并js和CSS,但是目前的使用起來不是特別好需要修改BundleConfig的代碼
前言
新建Asp.net MVC4項目的時候,在Global.asax.cs里面發(fā)現(xiàn)多了一句代碼
BundleConfig.RegisterBundles(BundleTable.Bundles)
google了以后終于弄清楚了這個的作用,發(fā)現(xiàn)這個東西確實非常實用,且功能強大,能夠壓縮合并js和CSS,但是目前的使用起來不是特別好,如果添加js或者css文件的話,需要修改BundleConfig的代碼。
這里我自己簡單修改了BundleConfig,對這個進行簡單的擴展。
下面貼出代碼
先貼配置文件BundleConfig.xml(文件放在網(wǎng)站目錄下路徑見代碼中變量BundleConfigPath)
復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8" ?>
<root>
<Scripts>
<Script Path="~/bundles/jquery">
<File>~/Scripts/jquery-{version}.js</File>
</Script>
<Script Path="~/bundles/jqueryui">
<File>~/Scripts/jquery-ui-{version}.js</File>
</Script>
<Script Path="~/bundles/jqueryval">
<File>~/Scripts/jquery.unobtrusive*</File>
<File>~/Scripts/jquery.validate*</File>
</Script>
<Script Path="~/bundles/modernizr">
<File>~/Scripts/modernizr-*</File>
</Script>
<Script Path="~/bb/aa">
<File>~/Views/Home/addda.js</File>
</Script>
</Scripts>
<Styles>
<Style Path="~/Content/themes/base/css">
<File>~/Content/themes/base/jquery.ui.core.css</File>
<File>~/Content/themes/base/jquery.ui.resizable.css</File>
<File>~/Content/themes/base/jquery.ui.selectable.css</File>
<File>~/Content/themes/base/jquery.ui.accordion.css</File>
<File>~/Content/themes/base/jquery.ui.autocomplete.css</File>
<File>~/Content/themes/base/jquery.ui.button.css</File>
<File>~/Content/themes/base/jquery.ui.dialog.css</File>
<File>~/Content/themes/base/jquery.ui.slider.css</File>
<File>~/Content/themes/base/jquery.ui.tabs.css</File>
<File>~/Content/themes/base/jquery.ui.datepicker.css</File>
<File>~/Content/themes/base/jquery.ui.progressbar.css</File>
<File>~/Content/themes/base/jquery.ui.theme.css</File>
</Style>
<Style Path="~/Content/css">
<File>~/Content/site.css</File>
</Style>
</Styles>
</root>

代碼文件:BundleConfig.cs
復(fù)制代碼 代碼如下:

public class BundleConfig
{
public static string BundleConfigPath = "~/Config/BundleConfig.xml";
/// <summary>
/// Register Bundles From XML
/// </summary>
/// <param name="bundles"></param>
public static void RegisterBundles(BundleCollection bundles)
{
XmlDocument doc = new XmlDocument();
doc.Load(HttpContext.Current.Server.MapPath(BundleConfigPath));
XmlNode root = doc.DocumentElement;
// Regester Script
XmlNodeList ScriptList = root.SelectNodes("Scripts/Script");
if (ScriptList != null && ScriptList.Count > 0)
{
foreach (XmlNode node in ScriptList)
{
string path = CheckNodeRegedit(node);
if (string.IsNullOrEmpty(path)) continue;
var bound = new ScriptBundle(path);
List<string> files = GetFilesFormNode(node);
if (files.Count > 0)
{
bound.Include(files.ToArray());
bundles.Add(bound);
}
}
}
// Regester Style
XmlNodeList StyleList = root.SelectNodes("Styles/Style");
if (StyleList != null && StyleList.Count > 0)
{
foreach (XmlNode node in StyleList)
{
string path = CheckNodeRegedit(node);
if (string.IsNullOrEmpty(path)) continue;
var bound = new StyleBundle(path);
List<string> files = GetFilesFormNode(node);
if (files.Count > 0)
{
bound.Include(files.ToArray());
bundles.Add(bound);
}
}
}
doc = null;
}
/// <summary>
/// 如果內(nèi)容為空則不添加
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private static List<string> GetFilesFormNode(XmlNode node)
{
List<string> files = new List<string>();
foreach (XmlNode nodeFile in node.ChildNodes)
{
if (!string.IsNullOrEmpty(nodeFile.InnerText.Trim()))
files.Add(nodeFile.InnerText.Trim());
}
return files;
}
/// <summary>
/// 檢查注冊的Node
/// </summary>
/// <param name="node"></param>
/// <returns></returns>
private static string CheckNodeRegedit(XmlNode node)
{
XmlAttribute pathAtt = node.Attributes["Path"];
string path = string.Empty;
if (pathAtt == null || string.IsNullOrEmpty(pathAtt.Value.Trim()) || node.ChildNodes.Count == 0)
return string.Empty;
else
return pathAtt.Value.Trim();
}
}

相關(guān)文章

  • python安裝pillow的三種方法

    python安裝pillow的三種方法

    本文python安裝pillow的三種方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • ASP.NET?MVC5網(wǎng)站開發(fā)之總體概述(一)

    ASP.NET?MVC5網(wǎng)站開發(fā)之總體概述(一)

    這篇文章主要為大家詳細(xì)介紹了ASP.NET?MVC5網(wǎng)站開發(fā)之總體概述,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • .Net Web Api中利用FluentValidate進行參數(shù)驗證的方法

    .Net Web Api中利用FluentValidate進行參數(shù)驗證的方法

    最近在做Web API,用到了流式驗證,就簡單的說說這個流式驗證,下面這篇文章主要給大家介紹了關(guān)于.Net Web Api中利用FluentValidate進行參數(shù)驗證的相關(guān)資料,,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • 概述.net開發(fā)過程中Bin目錄下面幾種文件格式

    概述.net開發(fā)過程中Bin目錄下面幾種文件格式

    本篇文章主要對項目發(fā)布的時候,經(jīng)常用到的幾個文件:.pdb、.xsd、.vshost.exe、.exe、.exe.config、.vshost.exe.config的作用進行介紹,具有一定的參考價值,需要的朋友可以看下
    2016-12-12
  • .Net Core微信服務(wù)商二次進件的開發(fā)

    .Net Core微信服務(wù)商二次進件的開發(fā)

    這篇文章主要介紹了.Net Core微信服務(wù)商二次進件的開發(fā),包括服務(wù)商證書獲取方法及查詢進件狀態(tài)的詳細(xì)代碼,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-10-10
  • C#中的Equals、RefrenceEquals和==的區(qū)別與聯(lián)系

    C#中的Equals、RefrenceEquals和==的區(qū)別與聯(lián)系

    C#中判斷兩個對象是否相等有Equals、RefrenceEquals和==三種,其中==為運算符,其它兩個為方法,而Equals又有兩種版本,一個是靜態(tài)的,一個是虛擬的,詳細(xì)了解可以參考本文
    2012-12-12
  • ASP.NET?MVC中的路由原理與用法

    ASP.NET?MVC中的路由原理與用法

    本文詳細(xì)講解了ASP.NET?MVC中的路由原理與用法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • .NET 純分頁代碼實例

    .NET 純分頁代碼實例

    這篇文章介紹了.NET 純分頁代碼實例,有需要的朋友可以參考一下
    2013-09-09
  • asp.net自動更新組件分享

    asp.net自動更新組件分享

    前兩天在博客上發(fā)布了一篇英文的自動更新組件文章Release a AutoUpdater tool,那么在這篇文章中,我們也對其功能進行一些簡單說明,這個組件非常簡單,所以大家可以下載進行一些改進。
    2010-10-10
  • 在ASP.NET中插入flash代碼實例

    在ASP.NET中插入flash代碼實例

    這篇文章介紹了在ASP.NET中插入flash代碼實例,有需要的朋友可以參考一下
    2013-11-11

最新評論