在我的控制器我使用模型登录这些工作罚款和模型是给予我正确的数据当我登录到帐户给我空对象引用
这是我的模型
public class LoginViewModel
{
[Required]
//[Display(Name = "Email")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
字符串
我在这里的行动
public ApplicationSignInManager SignInManager {
get { return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
}
private set { _signInManager = value; }
}
public async Task<ActionResult> LoginUser(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var user = UserManager.FindByName(model.UserName);
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
型
这是一个
public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
{
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
: base(userManager, authenticationManager)
{
}
public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user)
{
return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
}
public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
{
var d = new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
}
}
型
and here the error in the browser
这些是我的启动类,我配置了标识,
[assembly: OwinStartup(typeof(Baity.Startup))]
namespace Baity
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
型
3条答案
按热度按时间nszi6y051#
由于下面的行可以工作,
字符串
这意味着
SignInManager
没有在控制器中初始化。型
如果您分享
SignInManager
的初始化代码,我们可以为您提供更多帮助。在
Identity.Config.cs
中获取管理器型
在startup.cs中,
型
l5tcr1uw2#
我发现
_signInManager = signInManager;
在Controller类的构造函数中丢失了,所以要仔细检查。字符串
kb5ga3dv3#
我发现我的问题的答案是,在身份验证,这就是为什么它不为我工作
字符串