这曾经有效,但是我最近发现 ASP.NET 不再在 cookie 中缓存用户角色。我运行了一个提琴手跟踪,看起来 cookie 的值是空白的,并且过期日期是过去设置的。因此,cookie 不会在后续请求中发送,并且每次往返都会命中数据库。
我似乎找不到任何关于此的帖子。任何帮助都会很棒。谢谢!
网络配置:
<roleManager enabled="true" defaultProvider="MyRoleProvider" cacheRolesInCookie="true" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" createPersistentCookie="false">
<providers>
<clear />
<add name="MyRoleProvider" type="MyCompany.Core.Web.Providers.MyRoleProvider" connectionStringName="MainConnect" applicationName="MyApplication" />
</providers>
</roleManager>
提琴手响应(标题):
HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
Set-Cookie: .ASPXROLES=; expires=Tue, 12-Oct-1999 05:00:00 GMT; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Mon, 31 Dec 2012 01:14:19 GMT
Content-Length: 1381