【发布时间】:2018-01-29 08:18:15
【问题描述】:
我们的网站使用 MVC 和身份框架 2.0。在实时站点上(幸运的是)用户现在可以完美登录:
这是使这项工作附加到 Account 控制器的 Login 操作的代码:
public async Task<ActionResult> Login(vmAccountLogin model, string ReturnUrl)
{
// if problems with model, just redisplay form
if (!ModelState.IsValid)
{
return View(model);
}
// hangs on this line
var user = UserManager.FindByEmail(model.Email);
// if user not found for this email, abort with no clues
if (user == null)
当我构建项目并将 DLL 复制到实时服务器时,它可以完美运行。但是...
在我的测试版本中,这挂在显示的行上。大约十秒钟后,调试跳转到 Dispose 方法。我已经逐行检查了 web.config 文件以检查它们是否相同。我读过很多 SO 文章,但不认为其中任何一篇适用于这个问题。顺便说一下,这是 UserManager 调用,效果很好:
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
如果我启用 .NET 符号的调试,它会挂在 FindByEmail 方法调用上。 GetUserManager 调用在即时窗口中显示:
?HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
{wiseowl.ApplicationUserManager}
ClaimsIdentityFactory: {Microsoft.AspNet.Identity.ClaimsIdentityFactory<wiseowl.Models.ApplicationUser, string>}
DefaultAccountLockoutTimeSpan: {00:05:00}
EmailService: {wiseowl.EmailService}
MaxFailedAccessAttemptsBeforeLockout: 5
PasswordHasher: {Microsoft.AspNet.Identity.PasswordHasher}
PasswordValidator: {Microsoft.AspNet.Identity.PasswordValidator}
SmsService: {wiseowl.SmsService}
Store: {Microsoft.AspNet.Identity.EntityFramework.UserStore<wiseowl.Models.ApplicationUser>}
SupportsQueryableUsers: true
SupportsUserClaim: true
SupportsUserEmail: true
SupportsUserLockout: true
SupportsUserLogin: true
SupportsUserPassword: true
SupportsUserPhoneNumber: true
SupportsUserRole: true
SupportsUserSecurityStamp: true
SupportsUserTwoFactor: true
TwoFactorProviders: Count = 2
UserLockoutEnabledByDefault: true
UserTokenProvider: {Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<wiseowl.Models.ApplicationUser>}
UserValidator: {Microsoft.AspNet.Identity.UserValidator<wiseowl.Models.ApplicationUser>}
Users: {System.Data.Entity.DbSet<wiseowl.Models.ApplicationUser>}
_claimsFactory: {Microsoft.AspNet.Identity.ClaimsIdentityFactory<wiseowl.Models.ApplicationUser, string>}
_defaultLockout: {00:05:00}
_disposed: false
_factors: Count = 2
_passwordHasher: {Microsoft.AspNet.Identity.PasswordHasher}
_passwordValidator: {Microsoft.AspNet.Identity.PasswordValidator}
_userValidator: {Microsoft.AspNet.Identity.UserValidator<wiseowl.Models.ApplicationUser>}
请问大家有什么建议吗?
【问题讨论】:
-
他们在 dev 和 prod 中使用相同的连接字符串?
-
还有你为什么不使用
await UserManager.FindByEmailAsync,因为你已经在使用TPL(任务) -
您是否能够从您的开发环境成功连接到数据库?挂在那条线上很可能是由于与数据库服务器的连接缓慢/失败。
标签: c# asp.net-mvc asp.net-identity-2