【问题标题】:Reason for changes to ASP.NET Identity code in ASP.NET SPA template?更改 ASP.NET SPA 模板中的 ASP.NET 标识代码的原因?
【发布时间】:2015-02-10 04:57:55
【问题描述】:

对于 ASP.NET SPA 应用,VS2013 附带的代码模板与 VS2013 Updates 2/3/4 附带的代码模板有很大不同。作为参考,这是来自

的相同模板

VS2013:https://www.dropbox.com/s/nc9t691adg2q9ac/OldTemplate.zip?dl=0

VS2013更新4:https://www.dropbox.com/s/sk8qajyxy4kx4m3/NewTemplate.zip?dl=0

最大的不同似乎是使用原始模板登录无需回发,完全通过 JavaScript(这似乎与 SPA 精神保持一致)。但是在更高版本的模板中,登录期间会发生完整的回发。似乎与此主要更改有关的其他更改过多,例如,在旧版本中,ApplicationOAuthProvider.cs 中存在此方法:

public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
    {
        using (UserManager<IdentityUser> userManager = _userManagerFactory())
        {
            IdentityUser 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 userManager.CreateIdentityAsync(user,
                context.Options.AuthenticationType);
            ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user,
                CookieAuthenticationDefaults.AuthenticationType);
            AuthenticationProperties properties = CreateProperties(user.UserName);
            AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }
    }

新模板中完全省略了此方法。

希望能深入了解为何进行如此重大的更改。我没有看到任何优势,对于 SPA 风格的应用程序,我更喜欢没有回发。但也许我还应该考虑一些重要的安全或设计原因。

谢谢... -本

【问题讨论】:

  • 浏览未回答的标签。我会猜测答案,但请注意,我们现在已经快一年了,ASP.NET 5 RC1 正式发布。

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


【解决方案1】:

我的猜测是这是疏忽或缺乏时间。

如果它不是充满代码示例的最迷人的答案,我很抱歉......但是当您使用File &gt; New Project 时,SPA 模板并不是最常用的场景。

我明白为什么它不会像 WebApplication 那样多。

如果您对模板感兴趣,我建议您查看SideWaffle,其中包含大量可以帮助您入门的模板。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2019-02-02
    • 1970-01-01
    相关资源
    最近更新 更多