Я пытаюсь войти в систему с помощью Microsoft Authentication in. net Основное приложение, но оно выдает ошибку. Как сбой операции базы данных при обработке запроса Я получаю эту ошибку при попытке выполнить ниже. код
enter code here
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
{
returnUrl = returnUrl ?? Url.Content("~/");
// GetAsync the information about the user from the external login provider
var fname = Request.Form["Input.FirstName"].ToList().First();
if (string.IsNullOrEmpty(fname))
{
ErrorMessage = "FirstName Name is Required.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
}
var Lname = Request.Form["Input.LastName"].ToList().First();
if (string.IsNullOrEmpty(Lname))
{
ErrorMessage = "LastName Name is Required.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
}
var pNumber = Request.Form["Input.PhoneNumber"].ToList().First();
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
ErrorMessage = "Error loading external login information during confirmation.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
}
//if (ModelState.IsValid)
//{
//Todo: set all required fields
var user = new User { UserName = Input.Email, Email = Input.Email,FirstName= fname, LastName=Lname,PhoneNumber=pNumber,IsActive=true };
var searchKey = Input.Email.Split("@").Last();
var organization = _userRepository.SearchOrganization(searchKey);
if (organization != null)
user.OrganizationId = organization.Id;
var result = await _userManager.CreateAsync(user);
//Todo: Set Registered role
//Todo: Detect and assign organization
if (result.Succeeded)
{
result = await _userManager.AddLoginAsync(user, info);
if (result.Succeeded)
{
_userManager.AddToRoleAsync(user, SmartRole.RegisteredUser).Wait();
_userManager.AddToRoleAsync(user, SmartRole.Anonymous).Wait();
user.IsAdmin =
_signInManager.UserManager.IsInRoleAsync(user, "Administrator").Result;
await _signInManager.SignInAsync(user, isPersistent: false);
_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
return LocalRedirect(returnUrl);
}
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
//}
LoginProvider = info.LoginProvider;
ReturnUrl = returnUrl;
return Page();
}
я пытаюсь сравнить какой-то код с базой данных, когда я получаю эту ошибку
public Model.Organization SearchOrganization(string searchKey)
{
return DbContext.Organizations.FirstOrDefault(x =>x.URL.Equals(searchKey,StringComparison.OrdinalIgnoreCase));
}