【发布时间】:2015-08-27 21:44:54
【问题描述】:
我们能否调整默认 asp.net web api 2 身份提供程序的性能。
如果我不使用角色或声明,是否可以将它们从身份提供者生成的查询中排除。这可能有助于大大提高性能。
我指的是默认web api项目创建的ApplicationOAuthProvider.cs类。
它遵循的步骤是:
var user1 = await userManager.FindByNameAsync(context.UserName);
if (user1 == null)
{
context.SetError("invalid_grant", "The user is not registered.");
return;
}
//查询在这里执行一次
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
// 在这里再次执行查询
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
OAuthDefaults.AuthenticationType);
//这个又产生一个查询
ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
CookieAuthenticationDefaults.AuthenticationType);
//触发与上面相同的查询
AuthenticationProperties properties = CreateProperties(user.UserName);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
整个过程需要 4 秒。我在这里做错了吗? 我们可以消除一些流程/合并其中的一些并优化 一样。
谢谢
【问题讨论】:
-
您有什么证据表明空角色/声明表会导致性能问题?
-
查询很长,包括查询中不需要的所有表
-
长查询并不意味着运行成本高。并且空表不会对查询性能产生任何影响。你检查过 SQL 中的执行平原吗?
-
正如我所说,空表不应该导致任何性能问题。我建议您运行分析器并找出究竟是什么导致了问题。您的数据库中有多少用户?
-
这听起来并不多。探查器对失踪时间有何看法?什么最花时间?
标签: asp.net-web-api asp.net-identity