MVC3 中的 OutputCache 和授权过滤器
我正在读一本关于 MVC2 的书,在 OutputCache 部分中它指出:
警告在前面的“授权过滤器如何交互”部分中 与输出缓存,”我解释说 [Authorize] 有特殊的 确保未经授权的访问者无法获取敏感信息的行为 信息只是因为它已经被缓存了。 但是,除非你 专门防止它,缓存的输出仍然有可能 交付给与授权用户不同的授权用户 最初生成。 防止这种情况的一种方法是 将特定内容项的访问控制作为 授权过滤器(派生自 AuthorizeAttribute)而不是 只需在操作方法中内联执行授权逻辑, 因为AuthorizeAttribute知道如何避免被输出绕过 缓存。仔细测试,确保授权和输出 缓存以您期望的方式交互。
这在 MVC3 中仍然如此吗?
如果是的话,有什么方法可以防止这种情况发生? (因为书上的解释太模糊了)。
问候。
I am reading a book about MVC2, and in the OutputCache section it states:
Warning In the earlier section “How Authorization Filters Interact
with Output Caching,” I explained that [Authorize] has special
behavior to ensure that unauthorized visitors can’t obtain sensitive
information just because it’s already cached. However, unless you
specifically prevent it, it’s still possible that cached output could
be delivered to a different authorized user than the one for whom it
was originally generated. One way to prevent that would be to
implement your access control for a particular content item as an
authorization filter (derived from AuthorizeAttribute) instead of
simply enforcing authorization logic inline in an action method,
because AuthorizeAttribute knows how to avoid being bypassed by output
caching. Test carefully to ensure that authorization and output
caching are interacting in the way you expect.
Is this still true in MVC3?
If affirmative, what is the way to prevent that of happening? (because the explanation in the book is too vague).
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为是的。
当您使用OutPutCache缓存数据时,这些数据会被全局缓存。只要用户获得授权,该用户就会获取缓存的数据。
是的,我们有用于输出缓存的“VaryByParam”选项,但它也为传递的每个不同参数创建一个新的缓存。这意味着它仍然是全球性的。
因此,如果您想根据用户缓存不同的数据,outputcache 可能不是正确的方法。如果数据是特定于用户的,那么会话是正确的选择。这就是 session 存在的目的
I think it is.
When you are using OutPutCache to cache data, these data are cached globally. As long as a user is authorized, the user will get cached data.
Yes we have "VaryByParam" options for outputcache, but it also creates a new cache for every different parameter passed. which means it's still globally.
So if you want to cache different data based on users, outputcache may not be the right way doing it. If data is user specific, session is the right choice. it's what session lives for