gpt4 book ai didi

c# - ASP.NET MVC 中的多个 CSS 文件包

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:26 25 4
gpt4 key购买 nike

我在 ASP.Net MVC 中构建这个网站,基本上会有一个默认外观。根据进入门户的机构,颜色、横幅和问候语会发生变化。

例子:www.portal.com/Institution1

颜色:蓝色

横幅:照片1

www.portal.com/Institution2

颜色:绿色

横幅:照片2

我试图在 BundleConfig.cs 文件中完成此操作,但我还没有找到解决方案。

如果有人使用 www.portal.com 进入门户,我将使用:

bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));

如果有人使用 www.portal.com/Institution1 进入门户,我想使用:

bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/Institution1/Institution1.css",
"~/Content/site.css"));

如果有人使用 www.portal.com/Institution2 进入门户,我想使用:

bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/Institution2/Institution2.css",
"~/Content/site.css"));

有什么办法可以做到这一点吗?

最佳答案

没有一种特定的方法可以做到这一点。几年前我做过类似的事情。您可以定义一组主题并将用户或组织与已知主题相关联。包名可以像标识符一样使用。如果您以易于管理的方式布局您的内容,那么您可以将用户或组织与您提取内容的任何地方的样式或主题相关联。在对用户进行一般身份验证后,您可以在 IndexModel 或其他内容上设置一个属性,以便在加载主页时您可以使用类似以下内容访问所需的样式:

@Styles.Render(@Model.CurrentSyle.BundleName) 

我会做类似的事情:

public static void RegisterBundles(BundleCollection bundles)
{
//perhaps something like.
foreach (MyTheme theme in ThemeController.SelectAll())
AddThemeStyleBundle(bundles, theme.BundleName, theme.ThemeName);
}

private static void AddThemeStyleBundle(BundleCollection bundles,string bundleName, string themeName)
bundles.Add(new StyleImagePathBundle(bundlename).Include(
"~/Content/bootstrap.css",
String.Format("~/Content/{0}/Institution.css",themeName),
"~/Content/site.css"));
}

关于c# - ASP.NET MVC 中的多个 CSS 文件包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47641748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com