我正在努力在我的多租户应用程序中实现捆绑和缩小框架。
为了简单起见,这是一个小例子:
配置以下路由:
string mandatorConstraints = "Default|Other";
string defaultMandator = "Default";
routes.RouteExistingFiles = true;
routes.MapRoute("Content", "{mandator}/Content/{*filePath}", new { mandator = defaultMandator, controller = "Environment", action = "ContentFile" }, new { mandator = mandatorConstraints });
routes.MapRoute("Full", "{mandator}/{controller}/{action}/{id}", new { mandator = defaultMandator, controller = "Home", action = "Index", id = UrlParameter.Optional }, new { mandator = mandatorConstraints });
强制程序反映了连接字符串键以获取相应的数据库。
之后,我将(预)注册每个租户所需的所有捆绑包。
public static void RegisterBundles(BundleCollection bundles)
{
BundleTable.VirtualPathProvider = new ThemedVirtualPathProvider(BundleTable.VirtualPathProvider);
BundleTable.EnableOptimizations = true;
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Content/Scripts/jquery-{version}.js"));
foreach (string mandator in new[] { "Default", "Other" })
{
Bundle defaultStyles = new Bundle(string.Format("~/{0}/Content/css", mandator), new ThemableCssMinify());
defaultStyles.Include(string.Format("~/{0}/Content/Site.css", mandator));
defaultStyles.Include(string.Format("~/{0}/Content/custom.css", mandator));
bundles.Add(defaultStyles);
}
}
如果您使用以下URL访问应用程序,这似乎工作得很好:
http://localhost/Routing/default the correct styles are loaded.
Even if you switch to the other tenant http://localhost/Routing/other the according css gets loaded correctly.
但是如果我要在处理完样式表后更改样式表(Site2.css),我就无法使缓存无效。一旦浏览了关于控制器的操作,它应该使缓存无效。
附上你会找到一个示例解决方案:example
有什么想法吗?
从http://forums.asp.net/t/1952801.aspx?Multi+tenancy+bundling+minification+caching+issue
开始讨论