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
相关产品推荐
相关产品推荐

