asp.net web api 2身份表现

时间:2015-07-22 12:40:17

标签: asp.net-web-api asp.net-identity

我们可以调整默认的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秒。我在这里做错了什么?   我们可以消除一些过程/合并它们中的一些并优化它们   相同。

由于

0 个答案:

没有答案