我不知道这是否会发生,但在通过 MiniProfiler 查看我的一些应用程序后,我注意到 SimpleMembership 和 Roles 对服务器进行重复的 SQL 查询。
这是 miniprofiler 的结果:
http://localhost:49422/ActionMatrix/ActionMatrix?Length=0&D=23%2F03%2F2013&ProTyp=&ActTyp=&X-Requested-With=XMLHttpRequest
T+3.7 ms
Scalar
0.3 ms
QueryValue QueryValue GetUserId GetRolesForUser
SELECT [UID] FROM [Usernames] WHERE (UPPER([User]) = @0)
http://localhost:49422/ActionMatrix/ActionMatrix?Length=0&D=23%2F03%2F2013&ProTyp=&ActTyp=&X-Requested-With=XMLHttpRequest
T+4.4 ms
Reader
0.2 ms
MoveNext Query Query GetRolesForUser
SELECT r.RoleName FROM webpages_UsersInRoles u, webpages_Roles r Where (u.UserId = @0 and u.RoleId = r.RoleId) GROUP BY RoleName
http://localhost:49422/ActionMatrix/ActionMatrix?Length=0&D=23%2F03%2F2013&ProTyp=&ActTyp=&X-Requested-With=XMLHttpRequest
T+5.1 ms
DUPLICATE Scalar
0.2 ms
QueryValue QueryValue GetUserId GetRolesForUser MoveNext HasClaim IsInRole
SELECT [UID] FROM [Usernames] WHERE (UPPER([User]) = @0)
http://localhost:49422/ActionMatrix/ActionMatrix?Length=0&D=23%2F03%2F2013&ProTyp=&ActTyp=&X-Requested-With=XMLHttpRequest
T+5.7 ms
DUPLICATE Reader
0.1 ms
MoveNext Query Query GetRolesForUser MoveNext HasClaim IsInRole
SELECT r.RoleName FROM webpages_UsersInRoles u, webpages_Roles r Where (u.UserId = @0 and u.RoleId = r.RoleId) GROUP BY RoleName
也许它会检查两次?它肯定会减慢页面加载速度。没有全局过滤器,它只通过一个“授权”。有任何想法吗?