You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RoleManager.FindByNameAsync与IdentityServer数据库调用关联及性能排查

关于IdentityServer与RoleManager集成及性能问题的疑问
  • 维护一个采用IdentityServer进行身份认证的站点,近期发现站点偶尔出现卡顿,通过AppInsights定位到调用RoleManager.FindByNameAsync(name)的端点存在随机变慢的情况。
  • AppInsights显示该方法触发的SQL查询如下:
SELECT [t].[Id], [t].[Email], [t].[FirstName], [t].[LastName], [t].[UserName], [t].[CreatedAtUtc] AS [CreatedAt], [t].[EmailConfirmed], [t].[LastLoginUtc] AS [LastLogin], [t].[LockoutEnabled], [t].[LockoutEnd] AS [LockoutEndDateUtc], [claim].[ClaimType] AS [Type], [claim].[ClaimValue] AS [Value], [claim].[Id] AS [Id0]
FROM [UserClaims] AS [claim]
INNER JOIN (
    SELECT [user].*
    FROM [Users] AS [user]
    WHERE [user].[Id] IN (
        SELECT [claim0].[UserId]
        FROM [UserClaims] AS [claim0]
        WHERE ([claim0].[ClaimType] = @__type_0) AND ([claim0].[ClaimValue] = @__value_1)
    )
) AS [t] ON [claim].[UserId] = [t].[Id]
  • 经确认,数据库查询本身耗时不长(最多100ms),因此推测卡顿问题出在C#代码层面。
  • 核心疑问:RoleManager.FindByNameAsync是如何与IdentityServer集成的?RoleManager属于微软官方扩展组件,但在站点配置中未找到二者的关联设置(本人接触IdentityServer时间不长)。

内容的提问来源于stack exchange,提问作者daxu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 16:05:38