更改每个用户的捆绑包内容

本文关键字:包内容 用户 | 更新日期: 2023-09-27 17:57:03

我在ASP MVC web应用程序中使用带有CDN的捆绑包。

bundles.Add(new ScriptBundle("~/bundles/HomeJs", Util.BuildCDNURL("../../bundles/HomeJs"))
                .Include("~/Scripts/HomePage.js"));

据我所知,捆绑包是在App_Start((中注册的,我称之为

然而,我想为我的Util添加一些额外的逻辑。基于当前用户请求构建CDNURL((方法。在我的应用程序中,每个用户登录都有一个"使用CDN"值。

我可以根据每个用户的不同值来操作我的CDN路径吗?

更改每个用户的捆绑包内容

我使用以下内容来更改获取css文件的目录。您可以对CDN路径使用相同的东西来构建捆绑包。

public static class DynamicBundles
{
    public static IHtmlString RenderSkin(string skinDirectory)
    {            
        BundleTable.Bundles.Add(new StyleBundle("~/Content/css/" + skinDirectory).Include(
        "~/Content/" + skinDirectory + "/reset.css", 
        "~/Content/" + skinDirectory + "/site.css", 
        "~/Content/" + skinDirectory + "/grids.css"));
    return Styles.Render("~/Content/css/" + skinDirectory);
    }
}

然后在视图中使用,如下所示:

@DynamicBundles.RenderSkin(skinDirectory)