【问题标题】:asp.net web api 2 identity performanceasp.net web api 2 身份性能
【发布时间】: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


【解决方案1】:

我们的设置差不多。

每个请求都会发生这种情况吗?

我们在实体框架冷查询和视图生成方面遇到了很多问题,但是,“第二个”查询总是非常快。

如果是这种情况,您可以尝试使用带有 Identity 的 ADO.net,并为实体框架预生成视图。然而,这仍然是一个混乱的解决方案,我认为 MS 应该解决的问题。

The article 在身份方面仍然非常重要,并且通过实体框架“热身”。

【讨论】:

    猜你喜欢
    • 2013-09-28
    • 1970-01-01
    • 2023-04-08
    • 2017-10-22
    • 2016-07-17
    • 2015-01-12
    • 2012-06-16
    • 2020-02-05
    • 2014-01-28
    相关资源
    最近更新 更多