多租户应用程序的输出缓存,因主机名和文化而异
我在 ASP.NET MVC 中有一个多租户应用程序。将提供服务的应用程序实例仅是主机名的函数(我想类似于stackexchange)。
应用程序的每个实例可能具有不同的区域性设置(甚至是“自动”,以读取浏览器的语言并尝试使用它),并将相应地本地化。
在这种情况下,我想对我的某些操作进行一些输出缓存。所以,我的问题是:
如果输出完全依赖于主机名,多租户 ASP.NET MVC 应用程序实现输出缓存的可能性是什么? (即忽略本地化要求)?
与 (1) 相同,但现在考虑到输出也取决于区域性设置?
与 (2) 相同,但考虑到输出可能会随传递给操作的参数而变化?
在本例中,我考虑所有站点都从单个 IIS 网站运行。
I have a multi-tenant application in ASP.NET MVC. The instance of the application that will be served is function of the hostname alone (something along the lines of stackexchange, I suppose).
Each instance of the application might have a different culture setting (even "auto", to read the browser's language and try to use it), and will be localized accordingly.
In this situation, I'd like to do some output caching on some of my actions. So, my questions are:
What are the possibilities to achieve output caching of a multi-tenant ASP.NET MVC application, if the output depends exclusively on the hostname (ie, ignoring the localization requirement)?
Same as (1), but now considering that the output depends on the culture settings as well?
Same as (2), but considering that the output might vary with parameters that were passed to the action?
In this case, I'm considering that all the sites run from a single IIS website.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚想出了如何实现这一目标。
只需使用
VaryByHeader
属性,并将其设置为"host"
。这样做的可能性有很多。方法 1
使用
OutputCacheAttribute
传递所有需要的配置元素,包括VaryByHeader
:方法 2。
或者您可以将其设置为 Web.config 上的配置文件:
然后使用它:
方法 3。
或者您可以子类化
OutputCacheAttribute
并使用它:然后使用它:
I've just figured out how to achieve this.
Simply use the
VaryByHeader
property, set to"host"
. There are many possibilities to do so.Method 1
Use the
OutputCacheAttribute
passing all the needed configuration elements, includingVaryByHeader
:Method 2.
Or you could set it to a profile on the Web.config:
Then use it:
Method 3.
Or you can subclass the
OutputCacheAttribute
and use it:Then use it:
如果人们登陆此页面并正在寻找 asp.net 2.x 中的等效内容。该属性将如下所示:
您将需要添加中间件。您需要 此 nuget 包 和此代码:
更多详细信息请参见此处
In case people land on this page and are looking for the equivalent in asp.net 2.x. The attribute will look like this:
And you will need the middleware added. You need this nuget package and this code:
More details here