IamMax420
Log in system error
I was trying to make a log in system for my web app, but my code doesn't seem to work
using AplikacjaWeb.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace AplikacjaWeb.Pages.Registration
{
public class RegistrationModel : PageModel
{
private readonly UserManager<UserModel> _userManager;
private readonly SignInManager<UserModel> _signInManager;
public RegistrationModel(UserManager<UserModel> userManager, SignInManager<UserModel> signInManager)
{
_userManager = userManager;
_signInManager = signInManager;
}
[BindProperty]
public Rejestracja /*Registration in english*/ Input { get; set; }
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
if (ModelState.IsValid)
{
var user = new UserModel { UserName = Input.Username, Email = Input.Email, PasswordHash = Input.Password };
var result = await _userManager.CreateAsync(user, Input.Password);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToPage("/Index");
}
else
{
Console.WriteLine("Error");
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}
return RedirectToPage("/Index");
}
}
}
13 replies
object ref not set blah blah blah
atp i have no Idea what I did wrong. In the following function:
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
var result = await _signInManager.PasswordSignInAsync(Input1.Username, Input1.Password, false, false);
if (result.Succeeded)
{
return RedirectToPage("/Index");
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}
the PasswordManagerAsync() method is throwing the aforementioned exception3 replies
I'm getting an error "object reference not set to an instance of an object"
the code:
@model IEnumerable<WebApp.Models.Produkt>
<h1>a List</h1>
@if (Model == null || !Model.Any())
{
<p>No products available.</p>
}
else
{
@foreach (var product in Model)
{
if (product != null)
{
<li>
<b>@product.name</b> - @product.category
<a href="@Url.Action("Details", "Warehouse", new { id = product.id })">Details</a>
<button>Delete</button>
</li>
}
}
}
It appears that Model is null but I don't know how to fix it13 replies