Hi, I added a register form and a database driven authentication to a project I'm working on. Since then, I get a null reference error without seeing any validation summary when I try log in. The same thing happens when i try opening the register page. But errors occur when the app is reading something. I checked my web config and mapping but I couldnt find what causes the error. But I still think the error should at the mappings as I'm new to NHibernate. The whole source code can be found on: github.com/ismailousa/HastaneRandevu
C#:
[HttpPost]
public ActionResult Login(AuthLogin form, string returnUrl)
{
var user = Database.Session.Query<User>().FirstOrDefault(u => u.KimlikNo == form.KimlikNo);// I get the error here
if (user == null)
HastaneRandevu.Models.User.FakeHash();
if (user == null || !user.CheckPassword(form.Password))
ModelState.AddModelError("Kimlik No", "Kimlik No ya da Sifre yanlistir");
if (!ModelState.IsValid)
{
return View(form);
}
FormsAuthentication.SetAuthCookie(user.KimlikNo, true);
if (!string.IsNullOrWhiteSpace(returnUrl))
return Redirect(returnUrl);
if (User.IsInRole("Admin"))
return Content("Welcome Admin");
else if (User.IsInRole("Doktor"))
return Content("Welcome Doc");
else
return RedirectToRoute("Home");
}
C#:
public ActionResult New()
{
return View(new UsersNew()
{
Cinsiyetler = Database.Session.Query<Cinsiyet>().Select( //and here when trying to load sex and role info
cinsiyet => new CinsiyetRadioBox()
{
Id = cinsiyet.Id,
Name = cinsiyet.Name
}).ToList(),
Roles = Database.Session.Query<Role>().Select(
role => new RoleCheckBox()
{
Id = role.Id,
Name = role.Name
}).ToList()
});
}