C
C#8mo ago
aesthetics

[ASP.NET] ArgumentNullException: Value cannot be null. (Parameter 'viewData')

Earlier I attempted to change my ASP.NET Core MVC application to use User instead of IdentityUser. After attempting to change it, I couldn't get it to work and changed it back to IdentityUser. Now when I log-in, I get a ArgumentNullException. (I inherited from IdentityUser when using User) This is my Identity custom Login page
@page
@model LoginModel

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
</head>
<body class="bg-login">
<div class="centered" id="main-border">
<div class="text-center" style="padding-top: 50px">
<img src="~/images/loginlogo.png" width="214" height="60">
</div>
<form method="post">
<div class="centered" style="margin-top: 15px">
<input asp-for="Input.Email" class="inputdesign form-control" type="text" placeholder="Email"/>
<span asp-validation-for="Input.Email" class="text-danger"></span>
<input asp-for="Input.Password" class="inputdesign form-control" type="password" placeholder="Password" style="margin-top: 10px"/>
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="centered" style="margin-top: 10px;">
<button class="btn btn-outline-primary" type="submit" id="loginBtn">Log in</button>
</div>
<div class="centered" style="margin-top: 10px;">
<span asp-validation-summary="All" class="text-danger"></span>
</div>
</form>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js"></script>
</body>
</html>
@page
@model LoginModel

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
</head>
<body class="bg-login">
<div class="centered" id="main-border">
<div class="text-center" style="padding-top: 50px">
<img src="~/images/loginlogo.png" width="214" height="60">
</div>
<form method="post">
<div class="centered" style="margin-top: 15px">
<input asp-for="Input.Email" class="inputdesign form-control" type="text" placeholder="Email"/>
<span asp-validation-for="Input.Email" class="text-danger"></span>
<input asp-for="Input.Password" class="inputdesign form-control" type="password" placeholder="Password" style="margin-top: 10px"/>
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="centered" style="margin-top: 10px;">
<button class="btn btn-outline-primary" type="submit" id="loginBtn">Log in</button>
</div>
<div class="centered" style="margin-top: 10px;">
<span asp-validation-summary="All" class="text-danger"></span>
</div>
</form>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js"></script>
</body>
</html>
No description
1 Reply
aesthetics
aestheticsOP8mo ago
This is my Login.cshtml.cs file OnPost method
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
returnUrl ??= Url.Content("~/");

ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout");
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}

// If we got this far, something failed, redisplay form
return Page();
}
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
returnUrl ??= Url.Content("~/");

ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout");
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}

// If we got this far, something failed, redisplay form
return Page();
}
Want results from more Discord servers?
Add your server