3

I'm building this website in ASP.Net MVC that basically will have a default look. Depending of the institution entering the portal the color, banner and greetings will change.

Example: www.portal.com/Institution1

Color: Blue

Banner: Photo1

www.portal.com/Institution2

Color: Green

Banner: Photo2

I'm trying to accomplish this in the BundleConfig.cs file but I haven't found a solution.

If somebody enter the portal using www.portal.com I will use:

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

If somebody enter the portal using www.portal.com/Institution1 I want to use:

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

If somebody enter the portal using www.portal.com/Institution2 I want to use:

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

Is there any way of accomplished this?

1
  • yes, don't include those bundles into the page unless the user visits the relevant page. The code above just declares the bundles as usable, it doesn't actually cause them to be used. That is done in Layout and/or View pages. You're focusing on the wrong bit of code. Commented Dec 4, 2017 at 21:28

1 Answer 1

1

There is not one specific way to do this. I did something similar a few years back. You can define a set of themes and associate users or organizations with a known theme. The bundle name could be used like an identifier. If you layout your content in a manageable way then you can associated a user or organization with a style or theme from wherever you pull your content. After a user is authenticated generically, you could set a property on an IndexModel, or whatever, so that when the main page loads you can access the needed style using something like:

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

I would do something like:

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"));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.