ASP.NET MVC 缓存因身份验证而异

ASP.NET MVC Caching vary by authentication(ASP.NET MVC 缓存因身份验证而异)
本文介绍了ASP.NET MVC 缓存因身份验证而异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我最近 推出的微型网络应用程序上使用 ASP.NET Preview 5(即将升级到 Beta)和 LINQ2SQL一>.

I'm using ASP.NET Preview 5 (will upgrade soon to Beta) with LINQ2SQL on my recently launched tiny webapp.

我为自己的作品感到非常自豪,直到 Silverlight.net 在第一页上展示了它,而且它开始吸引了越来越多的访问者.

I was so proud of my work until Silverlight.net featured it on the first page and it started receiving a more than humble number of visitors.

出于某种原因,用户有时会收到 LINQ2SQL 抛出的Specified cast invalid" - 这是因为未经身份验证的用户被视为Guest"用户,并且控制器正在为每次点击加载有关用户Guest"的信息.

For some reason, users are sometimes getting "Specified cast invalid" thrown by the LINQ2SQL - this is because unauthenticated users are handled as a "Guest" user, and the Controller is loading information about the user "Guest" for each hit.

在第一页,顶部有一个欢迎 [USERNAME]",可以使用 甜甜圈缓存.

In the first page, there is a "Welcome [USERNAME]" on the top which can be easily cached using Donut Caching.

然而,在中间,有一个What is Dudlers.com"块只应向未经身份验证的用户显示,另一个关于你"块只应向经过身份验证的用户显示.这些块太复杂,无法使用 Donut Caching 进行缓存;它们太不同了,会很乱.

However, down in the middle, there is a "What is Dudlers.com" block which should only be shown to unauthenticated users, and another "About You" block which should only be shown to authenticated users. These blocks are too complicated to be cached using Donut Caching; they are way too different, it will be very messy.

我想根据用户的身份验证状态缓存第一个.因此,未经身份验证的用户(不用说,大多数)会获得访客"缓存页面,而其他经过身份验证的用户会看到一个全新的非缓存页面.

I would like to cache the first by depending on the authentication status of the user. So unauthenticated users (needless to say, the majority) get the "Guest" cached page, and other authenticated users are shown a fresh non-cached page.

是否可以选择根据身份验证指定缓存?就像是:[OutputCache(VaryBy = Authentication)]

Is there an option to specify caching varied by authentication? something like: [OutputCache(VaryBy = Authentication)]

或者是否有其他非 ASP.NET MVC 解决方案?(可能会调整 MS SQL)

Or is there another non-ASP.NET MVC solution? (perhaps tuning MS SQL)

我希望我的问题很清楚.我在同一台专用服务器上运行 Windows 2003 和 MS SQL 2005 Express.

I hope my question is clear. I'm running Windows 2003 and MS SQL 2005 Express on the same dedicated server.

谢谢!

推荐答案

您不必使用甜甜圈缓存机制.ASP.NET 具有 VaryByCustom 选项,允许您确定如何改变缓存.

You don't have to use the donut caching mechanism. ASP.NET has the VaryByCustom option, that allows you to determine how to vary the caching.

查看更多信息:http://aspadvice.com/blogs/ssmith/archive/2007/10/29/VaryByCustom-Caching-By-User.aspx

应该适用于 ASP.NET MVC.

Should work fine for ASP.NET MVC.

这篇关于ASP.NET MVC 缓存因身份验证而异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)