Question

Our asp.net mvc application currently has a single style for all our tenants.
We want to move to a system where depending on the tenant, a different css (actually a less variable file) is used.
The path to the file is predictable as ~\content\[tenantName]\style.css

Is the only way to configure [numberOfTenants] bundles and then have:

<%= Styles.Render("~/content/[tenantName]/style.css")%>

Is there a way to serve the correct css from the same virtual path, keeping the naming convention in mind, without having to configure separate bundles and without breaking caching?

Était-ce utile?

La solution

You need a three pronged approach to do multi-tenancy in ASP.NET MVC but it is possible (I've done it myself).

  • Write your own view engine that takes into account the client. You can get the client information from many places, but I usually just used the hostname. www.client.com == client-1.

  • Create helper methods to identity the client. Like I said above, use the host name and it should be pretty good, but also allow yourself to hardcode a client if you need to test.

  • Create a consistent folder structure to store images, css, and views.

A custom view engine will be your path to success.

Autres conseils

Use ResolveClientUrl!

   //Returns: ../HomePage.aspx
String ClientURL = ResolveClientUrl("~/HomePage.aspx");

//Returns: /HomePage.aspx
String RegURL = ResolveUrl("~/HomePage.aspx");

//Returns: C:\inetpub\wwwroot\MyProject\HomePage.aspx
String ServerMappedPath = Server.MapPath("~/HomePage.aspx");

//Returns: ~/HomePage.aspx
String appRelVirtPath = AppRelativeVirtualPath;

//Returns: http://localhost:4913/
String baseUrl = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;

//Returns: "http://localhost:4913/HomePage.aspx"
String absUri = Request.Url.AbsoluteUri;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top