【发布时间】: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