Soran
Asp Net MVC UserManager.Find Null Geliyor

Genel Tartışma
-
Arkadaşlar var user = _UserManager.Find(model.KullaniciAdi, model.Sifre);
Bu Satırda KullanıcıAdi Sifrede Dogru Geliyor _UserManager Neden Null Dönüyor IdentityUser Kütüphanesi Bilgisi Olan Varmı
private UserManager<ApplicationUser> _UserManager;
private RoleManager<ApplicationRole> _RoleManager;
// GET: Account
public AccountController()
{
var userStore = new UserStore<ApplicationUser>(new IdentityDataContext());
_UserManager = new UserManager<ApplicationUser>(userStore);
var roleStore = new RoleStore<ApplicationRole>(new IdentityDataContext());
_RoleManager = new RoleManager<ApplicationRole>(roleStore);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(Login model)
{
if(ModelState.IsValid)
{
var user = _UserManager.Find(model.KullaniciAdi, model.Sifre);
if (user != null)
{
var autManager = HttpContext.GetOwinContext().Authentication;
var identityClaims = _UserManager.CreateIdentity(user, "ApplicationCookie");
var autProperties = new AuthenticationProperties();
autProperties.IsPersistent = model.BeniHatirle;
autManager.SignIn(autProperties, identityClaims);
return RedirectToAction("Index","Home");
}
else
{
ModelState.AddModelError("UserLoginError", "Kullanıcı Giriş Yapma İşlemi Başarısız");
}
}
return View();
}
- Değiştirilmiş Tür Kyamuran SalibryamMicrosoft contingent staff, Moderator 15 Mayıs 2020 Cuma 07:19
Tüm Yanıtlar
-
Arkadaşlar Neden Gelen Verileri Kabul etmiyor Null Dönüyor Hatada Vermiyor Tip Uygunluğu veya Herhangi Bir Hata da Fırlatmıyor Nasıl Çözecem Bu İşi
private UserManager<ApplicationUser> _UserManager;
private RoleManager<ApplicationRole> _RoleManager;
// GET: Account
public AccountController()
{
var userStore = new UserStore<ApplicationUser>(new IdentityDataContext());
_UserManager = new UserManager<ApplicationUser>(userStore);
var roleStore = new RoleStore<ApplicationRole>(new IdentityDataContext());
_RoleManager = new RoleManager<ApplicationRole>(roleStore);
}
-
Arkadaşlar Neden Gelen Verileri Kabul etmiyor Null Dönüyor Hatada Vermiyor Tip Uygunluğu veya Herhangi Bir Hata da Fırlatmıyor Nasıl Çözecem Bu İşi
private UserManager<ApplicationUser> _UserManager;
private RoleManager<ApplicationRole> _RoleManager;
// GET: Account
public AccountController()
{
var userStore = new UserStore<ApplicationUser>(new IdentityDataContext());
_UserManager = new UserManager<ApplicationUser>(userStore);
var roleStore = new RoleStore<ApplicationRole>(new IdentityDataContext());
_RoleManager = new RoleManager<ApplicationRole>(roleStore);
}
https://www.google.com/search?q=asp.net+identity+find+user+by+email&oq=asp.net+identity+user+fi&aqs=chrome.1.69i57j0l7.8057j0j7&sourceid=chrome&ie=UTF-8 -
Sorunu Çözdüm Aslında Arkadaşlar Analamdığım Şu PasswordHash Property si DB de IdentityInitializer : CreateDatabaseIfNotExists<IdentityDataContext> Yani DB Yoksa DB Oluştur Metotunda Bir Kaçtane Hazır Kullanıclar Oluşturdum Lakin Login Ekranında PasswordHash de DB ye Yazılan Password Şifresini Kendi Çözemiyor Bu Biraz Kafa Karıştırıcı Yeni Kullanıcı Yarattıgımda Sorun Olmuyor Aşagıdaki Metotla Sorun Oluyor
if (!context.Users.Any(i => i.UserName == "caner1"))
{
var store = new UserStore<ApplicationUser>(context);
var manager = new UserManager<ApplicationUser>(store);
var user = new ApplicationUser() { Ad = "Caner", Soyad = "KORKMAZ", UserName = "caner1", Email = "ck01@hotmail.com", PasswordHash = "123456" };
manager.Create(user, "caner1");
manager.AddToRole(user.Id, "admin");
manager.AddToRole(user.Id, "user");
}